Reduce scope of global lock during RPC calls.

The first change is pure cleaning - the second one changes the business logic.