Applied @jwillis' correction to the second loop of DOPAIR2. dx_max was entering the external loop with the wrong sign.