Improved sweep_and_prune.py