fixed order of deletion so image still exists