Fix incorrect array length causing undefined errors