Ported the runFinalizers function.