fixing threading issues