Lots of development

Getting close to a working version, but plenty of debugging to do.