lots of refactoring and tidy up needed, getting there