Solution for Problem #5