Optimized function