Solution for problem four