public function setValues($values, array $files = array())
    {
        foreach ($this->getFields() as $name => $field) {
            $name = $field->getBaseName();
            $index = $field->getIndex();

            if ($index === null) { 
                if ($present = isset($values[$name])) {
                    $value =& $values[$name];
                }
            } else {
                if ($index) {
                    $present = true;
                    $tmp = &$values[$name];
                    foreach ($index as $part) {
                        if (isset($tmp[$part])) {
                            $tmp = &$tmp[$part];
                        } else {
                            $present = false;
                        }
                    }

                    if ($present) {
                        $value = $tmp;
                    }
                } else {
                    if ($present = isset($values[$name]) && is_array($values[$name])) {
                        $value = in_array($field->getValue(), $values[$name]);
                    }
                }
            }

            if ($field instanceof Fields\Multiple) {
                if (!$present) {
                    $value = array();
                }
                $field->setValues($value, (isset($files[$name])?$files[$name]:array()));
            } else {
                if ($present) {
                    $field->setValue($value, $files);
                } else {
                    if ($field instanceof Fields\FileField && isset($files[$name])) {
                        $field->setValue($files[$name]);
                    } else {
                        $field->setValue('');
                    }
                }
            }
        }
    }