Quite a lot of changes to the parser

Now it's quite a bit smarter.