Example 6, optimized