Server cleanup attempt 2

My refactoring here wasn't nearly as ambitious as I originally planned. I had grand ideas for how to clean up the code, but they turned out to be difficult to implement in practice, and I decided a much more gradual approach would probably be better. I clean up a few minor things in this pull request, and fixed the two reported server bugs, #79 and #64.