refactor message code