Do stuff before window is closed