Better thread wait logic, less sleep timers. plus other minor fixes