It's a tough age 
Keep up with the treats, try very hard to keep calm and appear relaxed at all the things he is not relaxed about. I know that's hard when you feel like crying 
I try to treat as soon as I see them but sometimes he'll spot one first and then start barking like mad
Have a think about the order you're doing this in. It reads like it happens in this order:
- You see another dog but your dog does not see them
- You treat your dog
- Your dog eats the treats
- Your dog spots the other dog
This is the wrong order (sorry!). What this does is risk your dog thinking treats are an indicator that another dog is present. So treats start to become a "get ready to react" sign.
What you want is this:
- You spot the other dog and mentally prep yourself, plan how to keep a distance from them, but otherwise do not react
- Your dog spots the other dog
- You give your dog a treat
- Your dog eats the treat
In this order, the other dog becomes a sign that treats are coming and - eventually - rather than worry about the other dog, your own dog sees them and then looks straight to you for the treat.
At first, your dog will bark after step 1, but perservere. Try not to ever get too close to the other dog so the greater distance you can achieve, the better. It just helps ensure your dog is a bit calmer and in a better state to eat the treat you offer. Repeat, repeat, repeat, repeat. It takes a lot of repetitions sometimes.
Don't feel bad or sad about cutting a walk short if you've both had some stress, such as already getting past one or two dogs. Much better to have short walks that you both enjoy than longer ones that end with you crying and the dog worried and stressed by it all. It's not failing to do an about turn and go straight home if you feel yourself getting overwhelmed.
And, as pp said, terriers do like to bark. It's their thing
. So expect some level of barking forever, though they do tend to calm down a little as they mature. In the end, you'll miss the barking. We lost our little JRT last year (known as Barky McBarkface) and now her barking is nothing but a bunch of funny stories we tell to remember her by.