fixing pagination issues and adding unit test for this part