refactored save method