fixed bug on terminate