You could get where the message goes by returning it from the refreshmessages to addmessage and from there to the variable and use it with removemessage or make them to same function etc... Still you'r saying that it removes all because you are using contain. How about using equal, or is there some reason why you wouldn't? You could actually make two funcs, one with containi and one with equal check.