Refactored server.cpp