Moved a lot of stuff out of main.c

No real reason. I just think it looks neater