Added minor improved version by double the size of array to prepare a working area