Move table rebuild immediately after setting the flag
Port performance improvements from PET/CBM version