protected function update_grade_item($courseid, $map, $key, $verbosescales, $value) {
        // Case of an id, only maps id of a grade_item.
        // This was idnumber.
        if (!$gradeitem = new grade_item(array('id' => $map[$key], 'courseid' => $courseid))) {
            // Supplied bad mapping, should not be possible since user
            // had to pick mapping.
            $this->cleanup_import(get_string('importfailed', 'grades'));
            return null;
        }

        // Check if grade item is locked if so, abort.
        if ($gradeitem->is_locked()) {
            $this->cleanup_import(get_string('gradeitemlocked', 'grades'));
            return null;
        }

        $newgrade = new stdClass();
        $newgrade->itemid = $gradeitem->id;
        if ($gradeitem->gradetype == GRADE_TYPE_SCALE and $verbosescales) {
            if ($value === '' or $value == '-') {
                $value = null; // No grade.
            } else {
                $scale = $gradeitem->load_scale();
                $scales = explode(',', $scale->scale);
                $scales = array_map('trim', $scales); // Hack - trim whitespace around scale options.
                array_unshift($scales, '-'); // Scales start at key 1.
                $key = array_search($value, $scales);
                if ($key === false) {
                    $this->cleanup_import(get_string('badgrade', 'grades'));
                    return null;
                }
                $value = $key;
            }
            $newgrade->finalgrade = $value;
        } else {
            if ($value === '' or $value == '-') {
                $value = null; // No grade.
            } else {
                // If the value has a local decimal or can correctly be unformatted, do it.
                $validvalue = unformat_float($value, true);
                if ($validvalue !== false) {
                    $value = $validvalue;
                } else {
                    // Non numeric grade value supplied, possibly mapped wrong column.
                    $this->cleanup_import(get_string('badgrade', 'grades'));
                    return null;
                }
            }
            $newgrade->finalgrade = $value;
        }
        $this->newgrades[] = $newgrade;
        return $this->newgrades;
    }