Refactor messages save or update