Fix threads issues