Fixes some threading issues