refactor message handlers