diff --git a/aconversions2/src/ConversionHandler.cpp b/aconversions2/src/ConversionHandler.cpp
index 3b051c1464ce0b2390ace9a87e88477d9170c74b..beac801337a6f53ca8cf08c5d3f4626b16db9cb4 100644
--- a/aconversions2/src/ConversionHandler.cpp
+++ b/aconversions2/src/ConversionHandler.cpp
@@ -2,7 +2,7 @@
  * ConversionHandler.cpp
  *
  *  Created on: 23. 2. 2014
- *	  Author: tomas
+ *	  Author: Tomas Pecka
  */
 
 #include "ConversionHandler.h"
@@ -23,23 +23,11 @@
 #include "regexp/convert/ToGrammarRightRGGlushkov.h"
 #include "regexp/convert/ToGrammarRightRGDerivation.h"
 
-#include "grammar/convert/ToGrammarRightRG.h"
-#include "grammar/convert/ToGrammarLeftRG.h"
-
-
-using namespace alib;
-using namespace automaton;
-using namespace grammar;
-using namespace regexp;
-using namespace sax;
-using namespace std;
-
-ConversionHandler::ConversionHandler( list<Token> & tokens, const std::string & target, const std::string & algorithm, std::ostream & out ) :
+ConversionHandler::ConversionHandler( std::list<sax::Token> & tokens, const std::string & target, const std::string & algorithm ) :
 	m_tokens( tokens ),
 	m_source( parseFormalismFromTokens( ) ),
 	m_target( parseFormalismFromString( target ) ),
-	m_algorithm( parseAlgorithmFromString( algorithm ) ),
-	m_out( out )
+	m_algorithm( parseAlgorithmFromString( algorithm ) )
 {
 
 }
@@ -47,10 +35,10 @@ ConversionHandler::ConversionHandler( list<Token> & tokens, const std::string &
 void ConversionHandler::convert( void )
 {
 	if( m_source == FINITE_AUTOMATON )
-		convertFSM( );
-	else if( isRegExp(m_source) )
+		convertFA( );
+	else if( m_source == REGULAR_EXPRESSION )
 		convertRE( );
-	else if( isGrammar( m_source ) )
+	else if( m_source == REGULAR_GRAMMAR )
 		convertRG( );
 	else
 		throw exception::AlibException( "ConversionHandler: Unknown source formalism." );
@@ -58,14 +46,12 @@ void ConversionHandler::convert( void )
 
 // ----------------------------------------------------------------------------
 
-void ConversionHandler::convertFSM( void )
+void ConversionHandler::convertFA( void )
 {
-	if( m_target == FINITE_AUTOMATON )
-		throw exception::AlibException( "ConversionHandler: No valid conversion from FSM to FSM." );
-	else if( isRegExp( m_target ) )
-		convertFSMtoRE( );
-	else if( isGrammar( m_target ) )
-		convertFSMtoRG( );
+	if( m_target == REGULAR_EXPRESSION )
+		convertFAtoRE( );
+	else if( m_target == REGULAR_GRAMMAR )
+		convertFAtoRG( );
 	else
 		throw exception::AlibException( "ConversionHandler: Unknown target formalism." );
 }
@@ -73,259 +59,157 @@ void ConversionHandler::convertFSM( void )
 void ConversionHandler::convertRE( void )
 {
 	if( m_target == FINITE_AUTOMATON )
-		convertREtoFSM( );
-	else if( isRegExp( m_target ) )
-		throw exception::AlibException( "ConversionHandler: No valid conversion from RE to RE." );
-	else if( isGrammar( m_target ) )
+		convertREtoFA( );
+	else if( m_target == REGULAR_GRAMMAR )
 		convertREtoRG( );
 	else
-		throw exception::AlibException( "ConversionHandler: Unknown target formalism." );
+		throw exception::AlibException( "ConversionHandler: Invalid target formalism." );
 }
 
 void ConversionHandler::convertRG( void )
 {
 	if( m_target == FINITE_AUTOMATON )
-		convertRGtoFSM( );
-	else if( isRegExp( m_target ) )
+		convertRGtoFA( );
+	else if( m_target == REGULAR_EXPRESSION )
 		convertRGtoRE( );
-	else if( isGrammar( m_target ) )
-		convertRGtoRG( );
 	else
-		throw exception::AlibException( "ConversionHandler: Unknown target formalism." );
+		throw exception::AlibException( "ConversionHandler: Invalid target formalism." );
 }
 
 // ----------------------------------------------------------------------------
 
-void ConversionHandler::convertFSMtoRE( void )
+void ConversionHandler::convertFAtoRE( void )
 {
 	const automaton::Automaton automaton = alib::DataFactory::fromTokens<automaton::Automaton>(m_tokens);
 
-	switch( m_algorithm )
-	{
-	case BRZOZOWSKI_ALGEBRAIC: {
-			std::string xmlMark = m_tokens.front( ).getData( );
-			if( xmlMark == "NFA") {
-				const automaton::NFA fsm = alib::DataFactory::fromTokens<automaton::NFA>( m_tokens );
-				regexp::UnboundedRegExp re = automaton::convert::ToRegExpAlgebraic::convert( fsm );
-				alib::DataFactory::toStdout(re);
-			} else if( xmlMark == "DFA") {
-				const automaton::DFA fsm = alib::DataFactory::fromTokens<automaton::DFA>( m_tokens );
-				regexp::UnboundedRegExp re = automaton::convert::ToRegExpAlgebraic::convert( fsm );
-				alib::DataFactory::toStdout(re);
-			} else {
-				throw exception::AlibException("Unrecognised formalism");
-			}
-			break;
-		}
+	switch( m_algorithm ) {
+	case BRZOZOWSKI_ALGEBRAIC:
+		alib::DataFactory::toStdout(automaton::convert::ToRegExpAlgebraic::convert( automaton ) );
+		break;
 	case STATE_ELIMINATION:
-	default: {
-			alib::DataFactory::toStdout(automaton::convert::ToRegExpStateElimination::convert(automaton));
-			break;
-		}
-	}
-}
-
-void ConversionHandler::convertFSMtoRG( void )
-{
-	if( m_target == RIGHT_REGULAR_GRAMMAR )
-		convertFSMtoRRG( );
-	else if( m_target == LEFT_REGULAR_GRAMMAR )
-		convertFSMtoLRG( );
-	else
-		throw exception::AlibException( "ConversionHandler::Unknown target formalism" );
-}
-
-void ConversionHandler::convertFSMtoRRG( void )
-{
-	const automaton::Automaton fsm = alib::DataFactory::fromTokens<automaton::Automaton>( m_tokens );
-
-	switch( m_algorithm )
-	{
-	default: {
-			alib::DataFactory::toStdout(automaton::convert::ToGrammarRightRG::convert(fsm));
-			break;
-		}
+	case DEFAULT:
+		alib::DataFactory::toStdout(automaton::convert::ToRegExpStateElimination::convert(automaton));
+		break;
+	default:
+		throw exception::AlibException( "ConversionHandler: Invalid algorithm." );
 	}
 }
 
-void ConversionHandler::convertFSMtoLRG( void )
+void ConversionHandler::convertFAtoRG( void )
 {
 	const automaton::Automaton fsm = alib::DataFactory::fromTokens<automaton::Automaton>( m_tokens );
 
-	switch( m_algorithm )
-	{
-	default: {
-			alib::DataFactory::toStdout(automaton::convert::ToGrammarLeftRG::convert(fsm));
-			break;
-		}
+	switch( m_algorithm ) {
+	case INCOMMING_TRANSITIONS:
+		alib::DataFactory::toStdout(automaton::convert::ToGrammarLeftRG::convert(fsm));
+		break;
+	case OUTGOING_TRANSITIONS:
+	case DEFAULT:
+		alib::DataFactory::toStdout(automaton::convert::ToGrammarRightRG::convert(fsm));
+		break;
+	default:
+		throw exception::AlibException( "ConversionHandler: Invalid algorithm." );
 	}
 }
 
 // ----------------------------------------------------------------------------
 
-void ConversionHandler::convertREtoFSM( void )
+void ConversionHandler::convertREtoFA( void )
 {
-    const regexp::RegExp regexp = alib::DataFactory::fromTokens<regexp::RegExp>(m_tokens);
-
-	switch( m_algorithm )
-	{
-	case BRZOZOWSKI_DERIVATION: {
-			alib::DataFactory::toStdout(regexp::convert::ToAutomatonDerivation::convert(regexp));
-			break;
-		}
-	case THOMPSON_NFA: {
-			alib::DataFactory::toStdout(regexp::convert::ToAutomatonThompson::convert(regexp));
-			break;
-		}
+	const regexp::RegExp regexp = alib::DataFactory::fromTokens<regexp::RegExp>(m_tokens);
+
+	switch( m_algorithm ) {
+	case BRZOZOWSKI_DERIVATION:
+		alib::DataFactory::toStdout(regexp::convert::ToAutomatonDerivation::convert(regexp));
+		break;
+	case THOMPSON_NFA:
+		alib::DataFactory::toStdout(regexp::convert::ToAutomatonThompson::convert(regexp));
+		break;
 	case GLUSHKOV_NFA:
-	default: {
-			alib::DataFactory::toStdout(regexp::convert::ToAutomatonGlushkov::convert(regexp));
-			break;
-		}
+	case DEFAULT:
+		alib::DataFactory::toStdout(regexp::convert::ToAutomatonGlushkov::convert(regexp));
+		break;
+	default:
+		throw exception::AlibException( "ConversionHandler: Invalid algorithm." );
 	}
 }
 
 void ConversionHandler::convertREtoRG( void )
-{
-	if( m_target == RIGHT_REGULAR_GRAMMAR )
-		convertREtoRRG( );
-	else if( m_target == LEFT_REGULAR_GRAMMAR )
-		throw exception::AlibException( "ConversionHandler:: RE to LRG is not implemented. Please convert to RRG and then to LRG." );
-	else
-		throw exception::AlibException( "ConversionHandler::Unknown target formalism" );
-}
-
-void ConversionHandler::convertREtoRRG( void )
 {
 	const regexp::RegExp regexp = alib::DataFactory::fromTokens<regexp::RegExp>(m_tokens);
 
-	switch(m_algorithm)
-	{
-	case BRZOZOWSKI_DERIVATION: {
-			alib::DataFactory::toStdout(regexp::convert::ToGrammarRightRGDerivation::convert(regexp));
-			break;
-		}
-	default: {
-			alib::DataFactory::toStdout(regexp::convert::ToGrammarRightRGGlushkov::convert(regexp));
-			break;
-		}
+	switch(m_algorithm) {
+	case BRZOZOWSKI_DERIVATION:
+		alib::DataFactory::toStdout(regexp::convert::ToGrammarRightRGDerivation::convert(regexp));
+		break;
+	case GLUSHKOV_NFA:
+	case DEFAULT:
+		alib::DataFactory::toStdout(regexp::convert::ToGrammarRightRGGlushkov::convert(regexp));
+		break;
+	default:
+		throw exception::AlibException( "ConversionHandler: Invalid algorithm." );
 	}
 }
 
 // ----------------------------------------------------------------------------
 
-void ConversionHandler::convertRGtoFSM( void )
-{
+void ConversionHandler::convertRGtoFA( void ) {
 	const grammar::Grammar grammar = alib::DataFactory::fromTokens<grammar::Grammar>(m_tokens);
-    alib::DataFactory::toStdout(grammar::convert::ToAutomaton::convert(grammar));
-}
-
-void ConversionHandler::convertRGtoRG( void )
-{
-	if( m_source == LEFT_REGULAR_GRAMMAR )
-		convertLRGtoRRG( );
-	else if( m_source == RIGHT_REGULAR_GRAMMAR )
-		convertRRGtoLRG( );
-	else if( m_source == LEFT_LINEAR_GRAMMAR )
-		throw exception::AlibException( "ConversionHandler: Conversions from linear grammars are not yet implemented." );
-	else if( m_source == RIGHT_LINEAR_GRAMMAR )
-		throw exception::AlibException( "ConversionHandler: Conversions from linear grammars are not yet implemented." );
-	else
-		throw exception::AlibException( "ConversionHandler: Unknown target formalism." );
+	switch( m_algorithm ) {
+	case DEFAULT:
+		alib::DataFactory::toStdout(grammar::convert::ToAutomaton::convert(grammar));
+		break;
+	default:
+		throw exception::AlibException( "ConversionHandler: Invalid algorithm." );
+	}
 }
 
-void ConversionHandler::convertRGtoRE( void )
-{
+void ConversionHandler::convertRGtoRE( void ) {
 	const grammar::Grammar grammar = alib::DataFactory::fromTokens<grammar::Grammar>(m_tokens);
 
-	switch( m_algorithm )
-	{
+	switch( m_algorithm ) {
 	case BRZOZOWSKI_ALGEBRAIC:
-	default:
+	case DEFAULT:
 		alib::DataFactory::toStdout(grammar::convert::ToRegExpAlgebraic::convert(grammar));
-        break;
-	}
-}
-
-void ConversionHandler::convertLRGtoRRG( void )
-{
-	const grammar::LeftRG lrg = alib::DataFactory::fromTokens<grammar::LeftRG>( m_tokens );
-
-	switch( m_algorithm )
-	{
-	default:
-		alib::DataFactory::toStdout(grammar::convert::ToGrammarRightRG::convert(lrg));
-		break;
-	}
-}
-
-void ConversionHandler::convertRRGtoLRG( void )
-{
-	const grammar::RightRG rrg = alib::DataFactory::fromTokens<grammar::RightRG>( m_tokens );
-
-	switch( m_algorithm )
-	{
+	       break;
 	default:
-		alib::DataFactory::toStdout(grammar::convert::ToGrammarLeftRG::convert(rrg));
-		break;
+		throw exception::AlibException( "ConversionHandler: Invalid algorithm." );
 	}
 }
 
 // ----------------------------------------------------------------------------
 
-ConversionHandler::TFormalism ConversionHandler::parseFormalismFromString( const std::string & _target ) const
-{
-	std::string target;
-	for( const auto & c : _target )
-		target.append( 1, tolower( c ) );
-
-	if( target == "fa" || target == "fsa" || target == "fsm" )
-		return FINITE_AUTOMATON;
-
-	if( target == "re" || target == "regexp" || target == "regex" )
-		return REGULAR_EXPRESSION;
-
-	if( target == "rrg" || target == "rg" || target == "grammar" )
-		return RIGHT_REGULAR_GRAMMAR;
+ConversionHandler::TFormalism ConversionHandler::parseFormalismFromString( const std::string & target ) const {
+	if( target == "fa" ) return FINITE_AUTOMATON;
+	if( target == "re" ) return REGULAR_EXPRESSION;
+	if( target == "rg" ) return REGULAR_GRAMMAR;
 
-	if( target == "lrg" )
-		return LEFT_REGULAR_GRAMMAR;
-
-	throw exception::AlibException( "ConversionHandler::Unknown target type" );
+	throw exception::AlibException( "ConversionHandler: Unknown target type." );
 }
 
-ConversionHandler::TFormalism ConversionHandler::parseFormalismFromTokens( void ) const
-{
-	std::string xmlMark = m_tokens.front( ).getData( );
-
-	if( xmlMark == alib::Names::AUTOMATON_NFA || xmlMark == alib::Names::AUTOMATON_DFA )
+ConversionHandler::TFormalism ConversionHandler::parseFormalismFromTokens( void ) const {
+	if( alib::api<automaton::Automaton>::first(m_tokens) )
 		return FINITE_AUTOMATON;
 
-	if( xmlMark == alib::Names::REGEXP_UNBOUNDED_REGEXP || xmlMark == alib::Names::REGEXP_FORMAL_REGEXP)
+	if( alib::api<regexp::RegExp>::first(m_tokens) )
 	        return REGULAR_EXPRESSION;
 
-	if( xmlMark == alib::Names::GRAMMAR_RIGHT_RG )
-		return RIGHT_REGULAR_GRAMMAR;
-
-	if( xmlMark == alib::Names::GRAMMAR_LEFT_RG )
-		return LEFT_REGULAR_GRAMMAR;
+	if( alib::api<grammar::Grammar>::first(m_tokens) )
+		return REGULAR_GRAMMAR;
 
 	throw exception::AlibException( "ConversionHandler: Invalid input formalism." );
 }
 
-ConversionHandler::TAlgorithm ConversionHandler::parseAlgorithmFromString( const std::string & _algorithm ) const
-{
-	std::string algorithm;
-	for( const auto & c : _algorithm )
-		algorithm.append( 1, tolower( c ) );
-
+ConversionHandler::TAlgorithm ConversionHandler::parseAlgorithmFromString( const std::string & algorithm ) const {
 	if( algorithm == "elimination" ) return STATE_ELIMINATION;
 	if( algorithm == "algebraic" ) return BRZOZOWSKI_ALGEBRAIC;
 	if( algorithm == "brzozowski" ) return BRZOZOWSKI_DERIVATION;
 	if( algorithm == "glushkov" ) return GLUSHKOV_NFA;
 	if( algorithm == "thompson" ) return THOMPSON_NFA;
+	if( algorithm == "incomming" ) return INCOMMING_TRANSITIONS;
+	if( algorithm == "outgoing" ) return OUTGOING_TRANSITIONS;
 
-	if( algorithm == "" ) return DEFAULT;
+	if( algorithm == "" || algorithm == "default" ) return DEFAULT;
 
 	throw exception::AlibException( "ConversionHandler:: Invalid algorithm. See help." );
 }
diff --git a/aconversions2/src/ConversionHandler.h b/aconversions2/src/ConversionHandler.h
index 6ef4568382c5b43eefd9c241a8080d80a161f862..96eab102afce74ef3bb7f9380ba21d943ec0a332 100644
--- a/aconversions2/src/ConversionHandler.h
+++ b/aconversions2/src/ConversionHandler.h
@@ -2,7 +2,7 @@
  * ConversionHandler.h
  *
  *  Created on: 23. 2. 2014
- *      Author: tomas
+ *      Author: Tomas Pecka
  */
 
 #ifndef ALGORITHMCHOOSER_H_
@@ -25,57 +25,30 @@ public:
     {
         DEFAULT,
 
-        /* FA to RE */
+        /* FA to RE + RG to RE */
         BRZOZOWSKI_ALGEBRAIC,
         STATE_ELIMINATION,
 
         /* FA to RG */
-        // FA to LRG,
-        // FA to RRG
+        INCOMMING_TRANSITIONS,
+        OUTGOING_TRANSITIONS,
 
-        /* RE to FA */
+        /* RE to FA + RE to RG */
         BRZOZOWSKI_DERIVATION,
         THOMPSON_NFA,
-        GLUSHKOV_NFA,
-
-        /* RE to RG */
-
+        GLUSHKOV_NFA
 
         /* RG to FA */
-        // LRG to FSM
-        // RRG to FSM
-
-        /* RG to RE */
-        // BRZOZOWSKI_ALGEBRAIC
-
-        /* RG to RG */
-        // RRG to LRG
-        // LRG to RRG
-
     };
 
     enum TFormalism
     {
         FINITE_AUTOMATON,
-
         REGULAR_GRAMMAR,
-        LEFT_REGULAR_GRAMMAR,
-        RIGHT_REGULAR_GRAMMAR,
-
-        LINEAR_GRAMMAR,
-        LEFT_LINEAR_GRAMMAR,
-        RIGHT_LINEAR_GRAMMAR,
-
-        REGULAR_EXPRESSION,
-
-        UNKNOWN,
+        REGULAR_EXPRESSION
     };
-    #define isGrammar(x) ( (x) == REGULAR_GRAMMAR || (x) == LEFT_REGULAR_GRAMMAR || (x) == RIGHT_REGULAR_GRAMMAR \
-                        || (x) == LINEAR_GRAMMAR  || (x) == LEFT_LINEAR_GRAMMAR  || (x) == RIGHT_LINEAR_GRAMMAR )
-
-    #define isRegExp(x) ( (x) == REGULAR_EXPRESSION )
 
-    ConversionHandler( std::list<sax::Token> & tokens, const std::string & target, const std::string & algorithm, std::ostream & out );
+    ConversionHandler( std::list<sax::Token> & tokens, const std::string & target, const std::string & algorithm );
     void convert( void );
 
 private:
@@ -83,31 +56,21 @@ private:
     TFormalism parseFormalismFromTokens( void ) const;
     TAlgorithm parseAlgorithmFromString( const std::string & _algorithm ) const;
 
-    void convertFSM( void );
-    void convertFSMtoRE( void );
-    void convertFSMtoRG( void );
-    void convertFSMtoLRG( void );
-    void convertFSMtoRRG( void );
+    void convertFA( void );
+    void convertFAtoRE( void );
+    void convertFAtoRG( void );
 
     void convertRE( void );
-    void convertREtoFSM( void );
+    void convertREtoFA( void );
     void convertREtoRG( void );
-    void convertREtoRRG( void );
 
     void convertRG( void );
-
-    void convertRGtoFSM( void );
-
+    void convertRGtoFA( void );
     void convertRGtoRE( void );
 
-    void convertRGtoRG( void );
-    void convertLRGtoRRG( void );
-    void convertRRGtoLRG( void );
-
     std::list<sax::Token> & m_tokens;
     TFormalism m_source, m_target;
     TAlgorithm m_algorithm;
-    std::ostream & m_out;
 };
 
 #endif /* ALGORITHMCHOOSER_H_ */
diff --git a/aconversions2/src/aconversion.cpp b/aconversions2/src/aconversion.cpp
index fa37f28c3e2932fd7ac8e31b6017c19238118941..66a3865773596b148ea9e00f6e4b8f5ca24ba176 100644
--- a/aconversions2/src/aconversion.cpp
+++ b/aconversions2/src/aconversion.cpp
@@ -5,131 +5,55 @@
  *	  Author: Tomas Pecka
  */
 
-#include <iostream>
-#include <getopt.h>
+#include <tclap/CmdLine.h>
 
 #include <sax/SaxParseInterface.h>
 #include <sax/ParserException.h>
 
 #include "ConversionHandler.h"
 
-#include <cstring>
-
-using namespace std;
-using namespace sax;
-using namespace alib;
-
-
-void help( void )
-{
-	cout << endl;
-	cout << "aconversion 0.01" << endl;
-	cout << "Converts between regular expressions, regular grammars and finite automaton." << endl;
-	cout << "Usage: aconversion -t FORMALISM [SWITCH...]" << endl << endl;
-	cout << "	-t, --target=FORMALISM \t Specifies target formalism. See --list-algorithms for available formalisms." << endl;
-	cout << "	-a, --algorithm=ALGORITHM \t Specifies algorithm to use. See --list-algorithms." << endl;
-	cout << "	-l, --list-algorithms \t Lists available algorithms." << endl;
-
-	cout << endl;
-}
-
-void list_algorithms( void )
-{
-	cout << "List of formalisms:" << endl;
-	cout << "\t For finite automaton use 'fsm', 'fsa' or 'fa'." << endl;
-	cout << "\t For regular expression use 'regexp', 're' or 'regex'." << endl;
-	cout << "\t For right regular grammar use 'rg', 'rrg' or 'grammar'." << endl;
-	cout << "\t For left regular grammar use 'lrg'." << endl;
-	cout << "This list is case-insensitive." << endl;
-
-	cout << endl;
-
-	cout << "List of available algorithms:" << endl;
-
-	cout << endl;
-	cout << "FA to RE:" << endl;
-	cout << "\t" << "'algebraic' - Uses Brzozowski algebraic method (regular equations)." << endl;
-	cout << "\t" << "'elimination' [Default] - Performs state elimination algorithm on NFA." << endl;
-
-	cout << endl;
-	cout << "FA to RRG:" << endl;
-	cout << "\t" << "[Default] - Converts to right regular grammar." << endl;
-
-	cout << endl;
-	cout << "FA to LRG:" << endl;
-	cout << "\t" << "[Default] - Converts to left regular grammar." << endl;
-
-	cout << endl;
-	cout << "RE to FA:" << endl;
-	cout << "\t" << "'brzozowski' - Uses Brzozowski's derivation method (WARNING: May get stuck in infinite loop)." << endl;
-	cout << "\t" << "'thompson' - Converts to finite automaton using Thompson's NFA Construction algorithm." << endl;
-	cout << "\t" << "'glushkov' [Default] - Converts to finite automaton using Gluskov's NFA algorithm." << endl;
-
-	cout << endl;
-	cout << "RE to RRG:" << endl;
-	cout << "\t" << "'brzozowski' - Uses Brzozowski's derivation method (WARNING: May get stuck in infinite loop)." << endl;
-	cout << "\t" << "'glushkov' [Default] - Converts to finite automaton using Gluskov's NFA algorithm." << endl;
-
-	cout << endl;
-	cout << "RG to FA:" << endl;
-	cout << "\t" << "[Default] - Converts right or left regular grammar to finite automaton." << endl;
-
-	cout << endl;
-	cout << "RG to RE:" << endl;
-	cout << "\t" << "'algebraic' [Default] - Uses Brzozowski algebraic method (regular equations)." << endl;
-
-	cout << endl;
-	cout << "RG to RG:" << endl;
-	cout << "\t" << "[Default] - Converts right to left regular grammar or vice versa." << endl;
-}
-
 int main(int argc, char* argv[])
 {
-	static struct option long_options[] = {
-		{"target",			required_argument,	NULL, 't'},
-		{"algorithm",		 required_argument,	NULL, 'a'},
-		{"version",			 no_argument,		NULL, 'v'},
-		{"help",				no_argument,		NULL, 'h'},
-		{"list-algorithms",	 no_argument,		NULL, 'l'},
-		{0, 0, 0, 0}
-	};
-
-	int long_index = 0, opt = 0;
-	std::string target, algorithm;
-
-	while( ( opt = getopt_long( argc, argv,"a:t:vhl", long_options, & long_index ) ) != -1 ) {
-		switch( opt )
-		{
-		case 'a':
-			algorithm.assign( optarg, strlen( optarg ) );
-			break;
-		case 't':
-			target.assign( optarg, strlen( optarg ) );
-			break;
-		case 'l':
-			list_algorithms( );
-			return 0;
-		case 'v':
-		case 'h':
-		default:
-			help( );
-			return 0;
-		}
-	}
-
 	try {
-		list<Token> tokens;
-		std::string input( istreambuf_iterator<char>( cin ), ( istreambuf_iterator<char>( ) ) );
-		SaxParseInterface::parseMemory( input, tokens );
+		TCLAP::CmdLine cmd("Converts between regular expressions, regular grammars and finite automaton.", ' ', "0.01");
+
+		std::vector<std::string> formalisms {"fa", "re", "rg" };
+		TCLAP::ValuesConstraint<std::string> allowedFormalisms( formalisms );
+		TCLAP::ValueArg<std::string> target(	"t",	"target",		"Specifies target formalism",		true,	"",	&allowedFormalisms);
+		cmd.add( target );
+
+		std::vector<std::string> algorithms{"algebraic", "elimination", "brzozowski", "glushkov", "thompson", "incomming", "outgoing", "default" };
+		TCLAP::ValuesConstraint<std::string> allowedAlgorithms( algorithms );
+		TCLAP::ValueArg<std::string> algorithm(	"a",	"algorithm",		"Specifies algorithm to use",		false,	"default",	&allowedAlgorithms);
+		cmd.add( algorithm );
+
+		TCLAP::ValueArg<std::string> input(	"i",	"input",	"input to convert",	false,	"-",		"file");
+		cmd.add( input );
+
+		cmd.parse(argc, argv);
+
+		std::list<sax::Token> inputTokens;
+		if(input.isSet()) {
+			if(input.getValue() == "-") {
+				sax::SaxParseInterface::parseStdin(inputTokens);
+			} else {
+				sax::SaxParseInterface::parseFile(input.getValue(), inputTokens);
+			}
+		} else {
+			sax::SaxParseInterface::parseStdin(inputTokens);
+		}
 
-		if(alib::api<exception::AlibException>::first(tokens)) throw alib::DataFactory::fromTokens<exception::AlibException>(tokens);
+		if(alib::api<exception::AlibException>::first(inputTokens)) throw alib::DataFactory::fromTokens<exception::AlibException>(inputTokens);
 
-		ConversionHandler conv( tokens, target, algorithm, cout );
+		ConversionHandler conv( inputTokens, target.getValue(), algorithm.getValue() );
 		conv.convert( );
 		return 0;
-	} catch (const exception::AlibException & exception ) {
+	} catch(const exception::AlibException& exception) {
 		alib::DataFactory::toStdout(exception);
 		return 1;
+	} catch(const TCLAP::ArgException& exception) {
+		std::cerr << exception.error() << std::endl;
+		return 2;
 	} catch (const std::exception& exception) {
 		std::cerr << "Exception caught: " << exception.what() << std::endl;
 		return 3;
diff --git a/anormalize2/src/anormalize.cpp b/anormalize2/src/anormalize.cpp
index eda475aa216398c4ac32532c0e45f6acb8a00920..f1cd10e088cc1769a5444c7f2ae5f0716fa59726 100644
--- a/anormalize2/src/anormalize.cpp
+++ b/anormalize2/src/anormalize.cpp
@@ -10,15 +10,29 @@
 #include "exception/AlibException.h"
 #include "factory/DataFactory.hpp"
 #include "automaton/simplify/Normalize.h"
+#include "grammar/convert/ToGrammarLeftRG.h"
+#include "grammar/convert/ToGrammarRightRG.h"
 
 int main(int argc, char** argv) {
 
 	try {
 		TCLAP::CmdLine cmd("Automaton normalize binary", ' ', "0.01");
 
-		TCLAP::ValueArg<std::string> input(	"a",	"automaton",	"Automaton to normalize",		false,	"-",		"file");
+		TCLAP::ValueArg<std::string> input(	"i",	"input",	"Input to normalize",		false,	"-",	"file");
 		cmd.add( input );
 
+		std::vector<std::string> forms {"leftRG", "rightRG" };
+		TCLAP::ValuesConstraint<std::string> formVals( forms );
+
+		TCLAP::ValueArg<std::string> form(	"f",	"form",		"Convert to different form",	false,	"",	&formVals);
+		cmd.add( form );
+
+		std::vector<std::string> inputTypes {"automaton", "grammar" };
+		TCLAP::ValuesConstraint<std::string> inputTypeVals( inputTypes );
+
+		TCLAP::ValueArg<std::string> labels(	"l",	"labels",	"Normalize labels",		false,	"",	&inputTypeVals);
+		cmd.add( labels );
+
 		cmd.parse(argc, argv);
 
 		std::list<sax::Token> tokens;
@@ -32,9 +46,21 @@ int main(int argc, char** argv) {
 			sax::SaxParseInterface::parseStdin(tokens);
 		}
 
-		alib::DataFactory::toStdout(automaton::simplify::Normalize::normalize(alib::DataFactory::fromTokens<automaton::Automaton>(tokens)));
-		return 0;
-
+		if(labels.getValue() == "automaton") {
+			alib::DataFactory::toStdout(automaton::simplify::Normalize::normalize(alib::DataFactory::fromTokens<automaton::Automaton>(tokens)));
+			return 0;
+		} else if(labels.getValue() == "grammar") {
+//			alib::DataFactory::toStdout(automaton::simplify::Normalize::normalize(alib::DataFactory::fromTokens<automaton::Automaton>(tokens)));
+			return 0;
+		} else if(form.getValue() == "leftRG") {
+			alib::DataFactory::toStdout(grammar::convert::ToGrammarLeftRG::convert(alib::DataFactory::fromTokens<grammar::Grammar>( tokens )));
+			return 0;
+		} else if(form.getValue() == "rightRG") {
+			alib::DataFactory::toStdout(grammar::convert::ToGrammarRightRG::convert(alib::DataFactory::fromTokens<grammar::Grammar>( tokens )));
+			return 0;
+		} else {
+			throw exception::AlibException("Invalid normalize command");
+		}
 	} catch (const exception::AlibException& exception) {
 		alib::DataFactory::toStdout(exception);
 		return 1;
@@ -49,3 +75,4 @@ int main(int argc, char** argv) {
 		return 127;
 	}
 }
+
diff --git a/tests.aconversion.sh b/tests.aconversion.sh
index f89f5666d156b479c93b39e8a2f34dae1a103ecf..e543c48fdeee3f5141f9867db3fdbcc36e906320 100755
--- a/tests.aconversion.sh
+++ b/tests.aconversion.sh
@@ -56,7 +56,7 @@ function generateNFA {
 # $1 = command for conversion. Output of such command must be (eps-)NFA !!
 # $2 = automaton
 function runTest2 {
-	MDFA="./aepsilon2 | ./atrim2 | ./adeterminize2 | ./atrim2 | ./aminimize2 | ./anormalize2"
+	MDFA="./aepsilon2 | ./atrim2 | ./adeterminize2 | ./atrim2 | ./aminimize2 | ./anormalize2 --labels automaton"
 
 	TMPNFA="nfa.xml"
 	echo "$2" > $TMPNFA
@@ -148,30 +148,30 @@ function runTest {
 
 # FA -> RG -> FA
 # covers: FA -> LRG, FA -> RRG, RRG <-> LRG, RRG -> FA, LRG -> FA
-runTest "./aconversions2 -t RRG | ./aconversions2 -t LRG | ./aconversions2 -t FA"
-runTest "./aconversions2 -t LRG | ./aconversions2 -t RRG | ./aconversions2 -t FA"
+runTest "./aconversions2 -t rg -a outgoing  | ./anormalize2 --form leftRG  | ./aconversions2 -t fa"
+runTest "./aconversions2 -t rg -a incomming | ./anormalize2 --form rightRG | ./aconversions2 -t fa"
 
 # FA -> RE -> FA
 # covers: FA -> RE (Brzozowski algebraic, elimination), RE -> FA (Brzozowski derivation, Thompson, Glushkov)
-runTest "./aconversions2 -t RE -a algebraic | ./aconversions2 -t FA -a brzozowski"
-runTest "./aconversions2 -t RE -a algebraic | ./aconversions2 -t FA -a thompson"
-runTest "./aconversions2 -t RE -a algebraic | ./aconversions2 -t FA -a glushkov "
-runTest "./aconversions2 -t RE -a elimination | ./aconversions2 -t FA -a brzozowski"
-runTest "./aconversions2 -t RE -a elimination | ./aconversions2 -t FA -a thompson"
-runTest "./aconversions2 -t RE -a elimination | ./aconversions2 -t FA -a glushkov"
+runTest "./aconversions2 -t re -a algebraic   | ./aconversions2 -t fa -a brzozowski"
+runTest "./aconversions2 -t re -a algebraic   | ./aconversions2 -t fa -a thompson"
+runTest "./aconversions2 -t re -a algebraic   | ./aconversions2 -t fa -a glushkov "
+runTest "./aconversions2 -t re -a elimination | ./aconversions2 -t fa -a brzozowski"
+runTest "./aconversions2 -t re -a elimination | ./aconversions2 -t fa -a thompson"
+runTest "./aconversions2 -t re -a elimination | ./aconversions2 -t fa -a glushkov"
 
 # FA -> RE -> RRG -> LRG -> FA
 # covers: FA -> RE (Brz. algebraic, elimination), RE -> RRG ( Brz. derivation, Glushkov), RRG -> LRG, LRG -> FA
-runTest "./aconversions2 -t RE -a algebraic | ./aconversions2 -t RRG -a brzozowski | ./aconversions2 -t LRG | ./aconversions2 -t FA"
-runTest "./aconversions2 -t RE -a algebraic | ./aconversions2 -t RRG -a glushkov | ./aconversions2 -t LRG | ./aconversions2 -t FA"
-runTest "./aconversions2 -t RE -a elimination | ./aconversions2 -t RRG -a brzozowski | ./aconversions2 -t LRG | ./aconversions2 -t FA"
-runTest "./aconversions2 -t RE -a elimination | ./aconversions2 -t RRG -a glushkov | ./aconversions2 -t LRG | ./aconversions2 -t FA"
+runTest "./aconversions2 -t re -a algebraic   | ./aconversions2 -t rg -a brzozowski | ./anormalize2 --form leftRG | ./aconversions2 -t fa"
+runTest "./aconversions2 -t re -a algebraic   | ./aconversions2 -t rg -a glushkov   | ./anormalize2 --form leftRG | ./aconversions2 -t fa"
+runTest "./aconversions2 -t re -a elimination | ./aconversions2 -t rg -a brzozowski | ./anormalize2 --form leftRG | ./aconversions2 -t fa"
+runTest "./aconversions2 -t re -a elimination | ./aconversions2 -t rg -a glushkov   | ./anormalize2 --form leftRG | ./aconversions2 -t fa"
 
 # FA -> RRG -> RE -> FA
 # covers: FA -> RRG, FA -> LRG, RRG -> RE, LRG -> RE, RE -> FA (Brz. derivation, Thompson, Glushkov)
-runTest "./aconversions2 -t RRG | ./aconversions2 -t RE | ./aconversions2 -t FA -a brzozowski"
-runTest "./aconversions2 -t LRG | ./aconversions2 -t RE | ./aconversions2 -t FA -a brzozowski"
-runTest "./aconversions2 -t RRG | ./aconversions2 -t RE | ./aconversions2 -t FA -a thompson"
-runTest "./aconversions2 -t LRG | ./aconversions2 -t RE | ./aconversions2 -t FA -a thompson"
-runTest "./aconversions2 -t RRG | ./aconversions2 -t RE | ./aconversions2 -t FA -a glushkov"
-runTest "./aconversions2 -t LRG | ./aconversions2 -t RE | ./aconversions2 -t FA -a glushkov"
+runTest "./aconversions2 -t rg -a outgoing  | ./aconversions2 -t re | ./aconversions2 -t fa -a brzozowski"
+runTest "./aconversions2 -t rg -a incomming | ./aconversions2 -t re | ./aconversions2 -t fa -a brzozowski"
+runTest "./aconversions2 -t rg -a outgoing  | ./aconversions2 -t re | ./aconversions2 -t fa -a thompson"
+runTest "./aconversions2 -t rg -a incomming | ./aconversions2 -t re | ./aconversions2 -t fa -a thompson"
+runTest "./aconversions2 -t rg -a outgoing  | ./aconversions2 -t re | ./aconversions2 -t fa -a glushkov"
+runTest "./aconversions2 -t rg -a incomming | ./aconversions2 -t re | ./aconversions2 -t fa -a glushkov"
diff --git a/tests.aderivation.aintegral.sh b/tests.aderivation.aintegral.sh
index 08c8bafbfa13e619ff4208c29bd8903262ef5ed0..81c16d7bc9ad4a43449616b3f262c9928832e0a3 100755
--- a/tests.aderivation.aintegral.sh
+++ b/tests.aderivation.aintegral.sh
@@ -21,7 +21,7 @@ cd bin-$1/
 # ----------------------------
 
 function regexpToMDFA {
-	echo "$1" | ./aconversions2 -t FSM | ./aepsilon2 | ./atrim2 | ./adeterminize2 | ./aminimize2 | ./anormalize2
+	echo "$1" | ./aconversions2 -t fa | ./aepsilon2 | ./atrim2 | ./adeterminize2 | ./aminimize2 | ./anormalize2 --labels automaton
 }
 
 function compareRegexp {