Refactored parser and improved parser error handling