Okay first thing, you can't do that head thing. Very bad to do. Unless you catch the dog while he is doing it, you can't punish it. It is still a puppy and won't know what it being punished for.
Other than that make sure to take it out frequently. Every hour or so. Try to remember the times it goes and make sure to take it out a little before then, most dogs go at the same time every day. Also make sure to stay out until he goes, (but after like 20-30 minutes take him in, he would have gone by then if he had to. But don't if he is sniffing and moving around, he is trying to find somewhere to go.)
When he goes praise him. Say something like "yay you went potty" and keep the phrase the same, repetition is key with dogs. When you come back give him a treat, but also try to teach him a trick like sit or shake to help with obedience.
Another good idea is to have a bell on the door you use when you take him out, if he is not able to get there put it on the door that leads to that area. Ring the bell when you go out and say "time to go out" or something like that and again keep the phrase the same. This will teach it to ring the bell when it needs to go and let you know before it has an accident.