modularized parser and some refactoring