Fixing thread issues