First working revision.  Many //TODO//s still in code.