WIP This is a huge work in progress.  If you want less terrible code, check out the previous commit