Cleaned up createAst() code