Re-solving problem 4