refactored pagination for key, keys, and startkey