Refactored the parser for a cleaner code structure