Separated functions into separate files and cleaned up some code.