better thread-checking