refactor send message function