Refactor messages to remove duplicate code