Making the "AT_EXIT" hack look a bit less like a copy-and-paste