moved the pagination logic to model