- refactoring to properly organize sending of messages to client