Well done for that, although the yellow wiring is very difficult to see against a black background.
This is wrong. Because it is in the loop function the fact that you do not initialise it correctly means that the other of members of the X array could be being stored anywhere and have values overridden by memory bytes being used for something else. This could explain the inconsistent results.
You need to define all the values of each array element.
By the way you should not change the contents of the first post apart from correcting the format of any code posted. It makes the following request for more information look silly for those reading the post from the start. That is why this is against the forum rules. Please read the rules in the post called "how to get the best out of this forum" at the start of each forum section.