private function listRecords()
    {
        $listNode = $this->response->createElement('ListRecords');
        if (isset($this->params['resumptionToken'])) {
            $records = $this->repository->listRecordsByToken($this->params['resumptionToken']);
        } else {
            list($metadataPrefix, $from, $until, $set) = $this->getRecordListParams();
            $records = $this->repository->listRecords($metadataPrefix, $from, $until, $set);

            if (!count($records->getItems())) {
                //maybe this is because someone tries to fetch from a set and we don't support that
                if ($set && !count($this->repository->listSets()->getItems())) {
                    throw new NoSetHierarchyException("The repository does not support sets.");
                }
                throw new NoRecordsMatchException(
                    "The combination of the values of the from, until, set and metadataPrefix arguments "
                    . "results in an empty list."
                );
            }
        }

        //create 'record' node for each record with a 'header', 'metadata' and possibly 'about' node
        foreach ($records->getItems() as $record) {
            $recordNode = $this->response->createElement('record');

            $header = $record->getHeader();
            $recordNode->appendChild($this->getRecordHeaderNode($header));

            // Only add metadata and about if the record is not deleted.
            if (!$header->isDeleted()) {
                $recordNode->appendChild($this->response->createElement('metadata'));

                // Push the record itself on the records stack
                array_push($this->records, $record->getMetadata());

                //only add an 'about' node if it's not null
                $about = $record->getAbout();
                if ($about !== null) {
                    $recordNode->appendChild($this->response->createElement('about', $about));
                }
            }

            $listNode->appendChild($recordNode);
        }

        $this->addResumptionToken($records, $listNode);

        return $listNode;
    }