parser refactoring and optimization