Refactored by moving sections of code into new files, tidying up import section