move pagination logic out of request