Fixing out-of-order bug caused by not using passed-back index ref on forEach