Saving messages to database.