Refactored Echo server code