I have the same problem with Louis. The root of the problem is the attack made on him by a large Whippet type dog when he was a puppy and we were walking on lead one day. Luckily for me I don't need to have Louis on lead very often, but when I do, and when he's off lead too, I do much the same as Jenny does with Brodie.
I trained a "watch me", which was easy with Louis as he's very food orientated. If he's on lead and a dog approaches that I know will have to pass us close by I use the "watch me" to keep him focussed on me.
If the dog won't be passing too close to us, when Louis is on lead or off, I use a "look at that" if I see the dog before Louis or at the same time, and reward him (quiet voice and lots of little treats) for every calm behaviour that he then does. Over time I've learned the distance that Louis is comfortable with when other dogs are nearby and I also watch the body language of other dogs to see if I think Louis will be able to stay calm near them. We have setbacks, and it's not easy to manage. I've had to teach myself to be calm and confident in order to help Louis and not to feel embarrassed or to be hard on myself when it goes wrong!
I think turning and walking away when Pepper has already started to react is too late, as he's already crossed the threshold and maybe even feels more fearful if the other dog is behind him and he can't see him properly. I'm sure there must be times when that's your only option, but if you can be watchful all the time and try a "watch me" or something before Pepper kicks off the situation should be easier to manage. Good luck