Fixed pagination, added conditional pagination