added pagination for query.