Fixed some bugs with pagination