refactor message display into a separate function