optimized version mostly failure