much, much faster way to compute the row arrays