Mary review6

I concentrated on the server.  Note the last commit for some bigger ideas about how to make the logic and architecture simpler.  Let me know when you have a free moment and we can go through my changes in detail.