Fixed locking after a discussion with some other developers.