Simplify lock code, try to make it more transparent.