Adds a bunch of tests for API pagination.
Removes a bunch of duplicate code in the API that was halfway refactored.
Removes more duplicate code.