Of course, when taking the dog outside, always keep him on a leash. If you have the time and patience, you can do some
training teaching Stop, Wait, Left, Right, etc. Of course, you would have to do this on leash and be consistent. It might take a while but using rewards may help also when he responds to these commands.
Good luck!!