public function getParams($namespace, $defaults, $params = null)
    {
        $session        = new Container($namespace);
        $sessionParams  = $session->params ?: array();
        $params         = $params ?: clone $this->getController()->getRequest()->getQuery();
        
        if ($params->get('clear')) {
            $sessionParams = array();
            unset($params['clear']);
        }
        
        $changed = false;
        foreach ($defaults as $key => $default) {
            if (is_numeric($key)) {
                $key = $default;
                $default = null;
            }
            $value = $params->get($key);
            if (null === $value) {
                if (isset($sessionParams[$key])) {
                    $params->set($key, $sessionParams[$key]);
                } elseif (null !== $default) {
                    $params->set($key, $default);
                    $sessionParams[$key] = $default;
                    $changed = true;
                }
            } else {
                if (!isset($sessionParams[$key]) || $sessionParams[$key] != $value) {
                    $changed = true;
                    $sessionParams[$key] = $value;
                }
            }
        }
        
        if ($changed) {
            unset($session->list);
            $session->params = $sessionParams;
        }
        
        return $params;
    }