refactor: pull out handleClientMessage