better way for checking for threads on terminate