Added code to extend the array in increasing steps rather than just by one, so that only O(log(N)) allocations are needed