Tidy all and document properly.
Refactor for testing (WIP).
Even more cunning refactor for testing.
Add proper tests.
remove debug.