Fixed possible race conditions and/or other possible problems with the timeouts.