Fixing an issue with threads