added pagination function