Added clearing of callbacks on terminate.