Solution for problem #7