Fix bugs in the var update