Merge in rewrite branch

Parser has been rewritten! Code is now much nicer and some features have been added.