Fix index out of bounds for a growing array