reorganize server code