when you come home from work and find dog shit on the floor, and then punish him, he doesnt know what you are punishing him for. the mess and the act (of pooping on the floor) are two separate things to him. he associates the punishment with whatever happens immediately prior to the punishment (i.e. you coming home).
you may say "but he knows, because he cowers when i come home"
if you are having this problem, then you apparently arent crate training, and are usually coming home to accidents. like i said before he associates the punishment with whatever immediately precedes it. in the dogs mind, when you walk through the door, he will be punished. he doesnt know why, just that its gonna happen.