Improved paginated query