In the simplest terms:
If you lean back too much, hold your leg when it's about straight up and down instead of extending all the way., then once you're leaning more forward, extend the held leg again and run like normal.
If you lean forward too much, it's tougher. You can bring an arm down and back to give yourself a push forward, extend the back ankle, or try contracting the front ankle and extending the front knee so your leg touches faster.
Maybe a combination of several of these techniques.
Eventually you'll get a feel for it.