websockets refactoring