Wrapping alert dismissal in an unload function