refactored a few files and tidied up