Fix variable type conversion bug