To prevent messing with the programmers code, you could see if on_exit != null. If it is, store its content and call that at the end of your cleanup code.