refactor API pagination