added comments and adjusted the construction of AST