Only restore closures if we got one

We get the transitive closure of an entity inside a loop, but restore it
outside.  So we should only do so if the loop trip count is greater than zero.