Save function debugged