Tidied up codebase to be a bit more testable

Thats not to say it is actually nicely testable.  That still needs work