Optimized the CR algorithm