refactored save