move all code to server.c