fixed server tests, some refactoring, and formatting