rewrote forall-next to reduce code duplication