I modified with a break and a check on p[n] -- would that work?