[IMP] Improve cursor management and add stop_after_upgrades option