Refactor and document `messageSanitize`