Fixed some bugs in the calculation of rows positions.