Fixing stupid error I introduced...
I didn't reasign the value of rangesArray after the call to concat. Fixed it.