move server implementation out