Attempt at fixing thread deadlocking