Some server refactoring