Add finer locks (code is not complete)