I have copied over a lot of code and started to fix includes.

I am going to represent the program's state in a single, global struct to make things neater.