changing where mutex is locked and unlocked