public function set($selector, $value)
    {
        $value = self::prepareToStore($value);

        // modify
        $arraySelector = explode('.', $selector);
        $chunksNum = count($arraySelector);

        // optimize one-level selector search
        if (1 == $chunksNum) {
            // update only if new value different from current
            if (!isset($this->data[$selector]) || $this->data[$selector] !== $value) {
                // modify
                $this->data[$selector] = $value;
                // mark field as modified
                $this->modifiedFields[] = $selector;
            }

            return $this;
        }

        // selector is nested
        $section = &$this->data;

        for ($i = 0; $i < $chunksNum - 1; $i++) {
            $field = $arraySelector[$i];

            if (!isset($section[$field])) {
                $section[$field] = array();
            } elseif (!is_array($section[$field])) {
                throw new Exception('Assigning sub-document to scalar value not allowed');
            }

            $section = &$section[$field];
        }

        // update only if new value different from current
        if (!isset($section[$arraySelector[$chunksNum - 1]]) || $section[$arraySelector[$chunksNum - 1]] !== $value) {
            // modify
            $section[$arraySelector[$chunksNum - 1]] = $value;
            // mark field as modified
            $this->modifiedFields[] = $selector;
        }

        return $this;
    }