fix bugs in pagination (was ignoring last page, and header)