Refactored code
Attempted to remove left recursion