You say you "finally got him home". Was he in hospital, or did you just get him? He may have been a caged pup, where he was,. and had no choice but to poop in his cage.
If you have not had him long-or changed his food,or are giving him too much, it will take awhile for him to adjust to a new life. At four months, he will still have to go out quite often, especially if he never had a routine. It is hard to determine, as you have not stated the back ground of the pup, how long you have had him?