Fixed a possible thread related crash.