expanded and refactored the parser