added prepareAST function