This is one big WTF. Why are you checking y, when you're checking the only two values that you're iterating over?