Made bits of the code a bit neater.
Improved testing.