New optimized version