Server: refactoring in main