some refactoring of parser