Improve the library code to avoid repeat instructions without a
direction change or a voltage change.