cleaned server code