diff --git a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx
index d14bbddfaa1feaf6b2bcd0df070abc0deed5b489..e6fe1e05908b54ceaec5be0fb16ed85be10e35b6 100644
--- a/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx
+++ b/alib2algo/src/regexp/simplify/RegExpOptimizeUnboundedPart.cxx
@@ -10,35 +10,22 @@ namespace regexp {
 namespace simplify {
 
 void RegExpOptimize::optimize( UnboundedRegExpAlternation & alt ) {
-	//while( A1( alt ) || A2( alt ) || A3( alt ) || A4( alt ) || A10( alt ) || V2( alt ) || V5( alt ) || V6( alt ) || X1( alt ) );
-	UnboundedRegExpElement* optimized = optimizeInner( alt );
-
-	UnboundedRegExpAlternation * alternationOptimized = dynamic_cast<UnboundedRegExpAlternation *>( optimized );
-	if( alternationOptimized ) {
-		alt = std::move( * alternationOptimized );
-		delete alternationOptimized;
-	} else {
-		alt = UnboundedRegExpAlternation { };
-		alt.appendElement( std::manage_move ( optimized ) );
-	}
+	for( unsigned i = 0; i < alt.getChildren ( ).size ( ); i++ )
+		alt.setChild( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner( * alt.getChildren ( ) [ i ] ) ), i );
+
+	while( A1( alt ) || A2( alt ) || A3( alt ) || A4( alt ) || A10( alt ) || V2( alt ) || V5( alt ) || V6( alt ) || X1( alt ) );
 }
 
 void RegExpOptimize::optimize( UnboundedRegExpConcatenation & concat ) {
-	//while( A5( concat ) || A6( concat ) || A7( concat ) || A8( concat ) || A9( concat ) || V8( concat ) );//|| V9( concat ) );
-	UnboundedRegExpElement* optimized = optimizeInner( concat );
-
-	UnboundedRegExpConcatenation * concatenationOptimized = dynamic_cast<UnboundedRegExpConcatenation *>( optimized );
-	if( concatenationOptimized ) {
-		concat = std::move( * concatenationOptimized );
-		delete concatenationOptimized;
-	} else {
-		concat = UnboundedRegExpConcatenation { };
-		concat.appendElement( std::manage_move ( optimized ) );
-	}
+	for( unsigned i = 0; i < concat.getChildren ( ).size ( ); i++ )
+		concat.setChild( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner( * concat.getChildren ( ) [ i ] ) ), i );
+
+	while( A5( concat ) || A6( concat ) || A7( concat ) || A8( concat ) || A9( concat ) || V8( concat ) );//|| V9( concat ) );
 }
 
 void RegExpOptimize::optimize( UnboundedRegExpIteration & iter ) {
-	/*do {
+	iter.setChild ( std::smart_ptr < UnboundedRegExpElement > ( optimizeInner ( * iter.getChild ( ) ) ) );
+	do {
 		// V1 is implemented right here
 		if( dynamic_cast<UnboundedRegExpEmpty*>( iter.getChild ( ).get() ) ) {
 			return;
@@ -47,16 +34,7 @@ void RegExpOptimize::optimize( UnboundedRegExpIteration & iter ) {
 		if( dynamic_cast<UnboundedRegExpEpsilon*>( iter.getChild ( ).get() ) ) {
 			return;
 		}
-	} while( A11( iter ) || V1( iter ) || V3( iter ) || V4( iter ) || V10( iter ) );*/
-	UnboundedRegExpElement* optimized = optimizeInner( iter );
-
-	UnboundedRegExpIteration * iterationOptimized = dynamic_cast<UnboundedRegExpIteration *>( optimized );
-	if( iterationOptimized ) {
-		iter = std::move( * iterationOptimized );
-		delete iterationOptimized;
-	} else {
-		iter = UnboundedRegExpIteration { std::manage_move ( optimized ) };
-	}
+	} while( A11( iter ) || V1( iter ) || V3( iter ) || V4( iter ) || V10( iter ) );
 }
 
 UnboundedRegExpElement* RegExpOptimize::optimizeInner( const UnboundedRegExpElement & node ) {