Rewrote the parser a bit to be more readable. No functional changes.