refactored, saving works now