Modularity

Moved some functions to separate files and fixed a few problems