Fixing threading issue