Refactor server for readability. Increase test coverage.