Misc refactoring tidying up etc