The statement
is within an if, which is within an if, which is within a while, which is within a while, which is within a while, which is within void loop().
And the result is:
and
which doesn't surprise me.
If you write procedures (which you test as you proceed) and use some indirection, the problem will probably clear itself for you, or at least become much more manageable.