refactored server code
added final solution