can we extract the message generation in a function? This way we don't have to copy the whole code.