added save function to save objects when user closes application