Use a mutex where appropriate