Safer thread stopping, should fix an assert