Moving server functionality into main