Optimized exercise 2