server: refactoring