A 4 month old puppy does not have the capability to control his bladder or bowels yet. It is up to you to take him out often enough and supervise well enough to avoid accidents. If he's still going in the house after going out every 2 hrs, then you need to take him out every hour, or every 45 minutes, or 30 minutes. Keep shortening the time between bathroom trips until he is no longer having accidents. Over time, you can gradually increase the time between trips out. You should be disciplining yourself if he goes in the house, not him. It's not his fault. He can't control it. You can control how many trips out he's getting and how much supervision he's getting. I seriously doubt he was fully housebroken in his previous home.
In between bathroom trips, you need to watch him with your undivided attention, or crate him. If you're watching him, you can grab him when he starts to sniff/circle/squat and run outside.
When he does go outside, reward him! Reward him outside when he's done going; don't wait to get back into the apartment (or he'll think he's getting rewarded for going in the apartment).