refactor save method