Simplify lock code, try to make it more transparent.

This is mainly to try to make some of this code more transparent.  The change of the interface of AcceptEvent might not be necessary.