Modularised source files

Basically split the code out so it's not one big fucking mess in main.c