Avoiding improper use of threads