fix paging issues at begin and end page