WebSocket - refactoring bits and pieces to make testing easier.