Code

As I say in the commit message, these changes were to help me clarify what was happening in the plugin and thought you might like them as well. This is based off the changes in #1 so make sure to merge that one first. If it needs rebasing just say so.