created addMessages function