Solution for Problem #39