fix issues with paging at begin and end pages