refactor message type logic