refactorised the code for index url used paginate_by in the index url