Imo This is the issue.
You are checking for indexes that do not exist.
You can:
- use for each loop: it will only check within the length of the array.
- Place is valid nodes after the Get.
Youll still ned is valid using for each, but its better if you plan to not have a fixed size for the array.