Changed from recursive-descent parsing to an iterative approach