Improved exercise 4