Added paginate function to Query