Fixed a bug in refreshVar/Type

When refreshing variables, it is important that multiple occurrences of the same
variable get refreshed to an identical new variable.