fixed index error caused by miscalculating max iterations. fixed repeateveryuntil to be deterministic.