Fix bug when array is not properly resized