private Map<String, String> getVariables(long processInstanceId) {
    Command<?> cmd = new FindVariableInstancesCommand(processInstanceId);

    Object result =
        internalDoKieSessionOperation(
            cmd, "Unable to retrieve process variables from process instance " + processInstanceId);
    List<VariableInstanceLog> varInstLogList = (List<VariableInstanceLog>) result;

    Map<String, String> vars = new HashMap<String, String>();
    if (varInstLogList.isEmpty()) {
      return vars;
    }

    Map<String, VariableInstanceLog> varLogMap = new HashMap<String, VariableInstanceLog>();
    for (VariableInstanceLog varLog : varInstLogList) {
      String varId = varLog.getVariableId();
      VariableInstanceLog prevVarLog = varLogMap.put(varId, varLog);
      if (prevVarLog != null) {
        if (prevVarLog.getDate().after(varLog.getDate())) {
          varLogMap.put(varId, prevVarLog);
        }
      }
    }

    for (Entry<String, VariableInstanceLog> varEntry : varLogMap.entrySet()) {
      vars.put(varEntry.getKey(), varEntry.getValue().getValue());
    }

    return vars;
  }