Fix bug with array length (unsure of cause)