refactor

cleaned up a lot of code.
broke out all the functions into files