Factor server code into a separate file