more clean up of the server code - made some helper functions