Refactored some of the parser code