homework3 - improve problem 4