Split into seperate files

Additional cleanup in global variables