Fix array length issue

We now reset the array length when an array shrinks.