Separated functions into separate files
Tidied up code