Solution to problem #6