added better check for saving