Optimized version