First big commit

This is the first big commit of code. I am going to tidy it up a lot,
but I want a backup of this code.