fix checking unset array values, deduplicate code, remove file from cache if it could not be stored in the objectstore