fix RangeError problem for large arrays