Speedup and fix double-iteration.