improved paging code