Added some fixes to the calculations for the pagination.