Fixing threading issues