refactort message to function