Refactor server implementation