add pagination function to index