added pagination and bug fix