Refactoring some parser code