Still trying to fix end of thread condition