Refactor For Testing

Addresses #12. Comments welcome from anyone.

@philbooth, when you get some time I think this is worth chatting through – I have a bunch of questions (mainly regarding some of my decisions in writing unit tests).

Took long enough, but we actually have tests for everything now! Should give us some confidence to tackle new features.