change locking to a mutex