added the functionality of pagination