make the parser algorithm more readable by adding helper methods

@radumereuta please review.