refactor parser to be clearer and not use global variables