modified solution to problem 5-4