refactor the server to make it easy to start from test