Controlling direction of unipolar stepper with buttons

This is working as long as the respective button is pressed. When released, it kind of stutters along. I am probably not describing what I want clearly. On either side of the printer carriage there is a limit switch. When this is pressed, I want the motor reversed. At that moment, the switch will go low again. The problem is writing code that will disregard the low state but send the mechanism to the switch at the opposite end. That is what the count business (0,1) was intended to achieve. 0 for left, 1 for right.