public function process()
    {
        $state = $this->getState();
        $variableIdentifier = $this->getExpression()->getIdentifier();
        $weightIdentifier = $this->getExpression()->getWeightIdentifier();

        $variable = $state->getVariable($variableIdentifier);
        if (empty($variable)) {
            return null;
        }

        $variableValue = $state[$variableIdentifier];

        if ($variable->isNull()) {
            return $variableValue; // Even if empty string, it is considered by QTI as null.
        }

        // We have a value for this variable, is it weighted?
        if ($state instanceof AssessmentTestSession) {

            try {
                $vIdentifier = new VariableIdentifier($variableIdentifier);
                if ($vIdentifier->hasPrefix() === true && empty($weightIdentifier) === false) {
                    $weight = $state->getWeight($vIdentifier->getPrefix() . '.' . $weightIdentifier);
                    $baseType = $variableValue->getBaseType();
                    $cardinality = $variableValue->getCardinality();

                    // From IMS QTI:
                    // Weights only apply to item variables with base types integer and float.
                    // If the item variable is of any other type the weight is ignored.
                    if (!empty($weight) && ($baseType === BaseType::INTEGER || $baseType === BaseType::FLOAT)) {

                        if ($cardinality === Cardinality::SINGLE) {
                            return new QtiFloat($variableValue->getValue() * $weight->getValue());
                        } elseif ($cardinality === Cardinality::MULTIPLE || $cardinality === Cardinality::ORDERED) {

                            // variableValue is an object, the weighting should not
                            // affect the content of the state so a new container is created.
                            $finalValue = ($cardinality === Cardinality::MULTIPLE) ? new MultipleContainer(BaseType::FLOAT) : new OrderedContainer(BaseType::FLOAT);
                            for ($i = 0; $i < count($variableValue); $i++) {
                                if ($variableValue[$i] !== null) {
                                    $finalValue[] = new QtiFloat($variableValue[$i]->getValue() * $weight->getValue()) ;
                                } else {
                                    $finalValue[] = null;
                                }
                            }

                            return $finalValue;
                        }
                    } else {
                        return $variableValue;
                    }
                } else {
                    return $variableValue;
                }
            } catch (InvalidArgumentException $e) {
                // Invalid $variableIdentifier.
                $msg = "Invalid identifier '${variableIdentifier}' given for variable identifier.";
                throw new ExpressionProcessingException($msg, $this, ExpressionProcessingException::NONEXISTENT_VARIABLE, $e);
            }

        } else {
            return $variableValue;
        }
    }