Fixed another possible race condition and improved the Multithread test to check the reference count