You will have to keep in mind that a dog has a 1.3 second associative memory. This means that they can link to a particular behaviour to the consequence of that behaviour for only 1.3 seconds. You have this small window of opportunity to either reward or correct a behaviour.
When we try to punish them or yell at them after the act has already happened. They do not understand our reaction. Unless we don't catch them in the act and react within that 1.3 second, it is not productive to react.Be careful of the association that your dog is making during any of these events. Your dog will most likely make a connection only in the 1.3 seconds. Any appreciation or reaction to their behaviour has to take place quickly. Bring home a crate so that you don't miss out on their activities to make a proper connection.