This should take into account that there might be variables already that shouldn't be cleared out. I think there is some other JS code that handles this somewhere around here.