Parser refactoring to make it vaguely understandable