protected function _write($options, $defaults) {
		$template = $this->_template;
		$trimmed = true;
		$options += ['args' => ''];

		foreach (array_reverse($this->_keys, true) as $key) {
			$value =& $options[$key];
			$pattern = isset($this->_subPatterns[$key]) ? ":{$this->_subPatterns[$key]}" : '';
			$rpl = "{:{$key}{$pattern}}";
			$len = strlen($rpl) * -1;

			if ($trimmed && isset($defaults[$key]) && $value == $defaults[$key]) {
				if (substr($template, $len) == $rpl) {
					$template = rtrim(substr($template, 0, $len), '/');
					continue;
				}
			}
			if ($value === null) {
				$template = str_replace("/{$rpl}", '', $template);
				continue;
			}
			if ($key !== 'args') {
				$trimmed = false;
			}
			$template = str_replace($rpl, $value, $template);
		}
		return $template ?: '/';
	}