Initial commit

This is the first working code. Needs some serious cleaning/commenting.