Solution to problem #4