private function appendPathAndFilterExisting(array $references, $nestedPath, $flags = 0)
    {
        $result = array();

        foreach ($references as $reference) {
            // Filter out null values
            // Links should be followed before calling this method
            if (null === $reference) {
                continue;
            }

            $nestedReference = rtrim($reference, '/').'/'.$nestedPath;

            if (file_exists($nestedReference)) {
                $result[] = $nestedReference;

                if ($flags & self::STOP_ON_FIRST) {
                    return $result;
                }
            }
        }

        return $result;
    }