cleanup server code and added comments