Partial solution to the fourth challenge.