Server refactoring and unit test additions