Fixed a threading issue