Move row dimension computation inside the loop.