Fixed so that it can handle case of 0 nrecords for rotation