Loop to explore packages with a simple heuristic to prevent reinstallations