That's a better solution for sure, but I'm curious why your code didn't do what you wanted. Any chance the numberOfCells and cellsPointerNumber don't have the values you think they do? Try just using array.length instead and see what happens.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi