Refactored server code'