Optimized version.