Refactor to define a Parser class.