Fix scoping issue in unload