Fixed the ugly row-permutation mess