Loop Logic Issue:
You're using else { x++; } in your loop, which could be incrementing x unnecessarily. This could cause the loop to skip over entries or exit prematurely. Remove the else { x++; } line and just rely on the for loop's natural increment.