Thread and SpinLock improved, no more memory leaks