fixed boundary error in paging code