Initial commit. Completely untested and a little bit gnarly. Needs some cleaning up.