Rewrote parser to make it clearer.