refractored some server code