added pagination and updated index function