added filtering and pagination logic.