Put paging commands in right place

Otherwise the total number of pages would be wrong.