Fix pagination() to get the right total number of pages