Why does adding an 'if' effect my state machine?

Yes, this is the opposite of what you need. Please post the whole thing. Or else change what you posted to make it a complete, compilable sketch.