optimized implementation