small refactoring for more flexibility when listening to websockets