Major refactoring
Tidy up prior to major rewrite