Move server handling code out to server.go