Fix the variable overwrite bug