Refactor pagination parts to separate function
Merge pull request #38 from Recras/query-refactoring

Refactor pagination parts to separate function