Move destroy to at_exit handler