Refactoring parser: Using recursion instead of while loop