Fixing a bug where the refresh event variable was global