Move server-starting into a function