Updating compatibility to Craft 2.2 and a few tidy-ups

The plugin didn't work for me in Craft 2.2, so I've updated it and implemented a few tidy-ups (hope that's OK).