optimize row coloring function (critical)