Server code refactoring