Minor refactoring
Simple version of optimizeAst implemented