giving up on refactoring paging functions
tidied up