refactored some files and tidied up using