Refactor client-server websockets