Avoid using defer

It sounds it is better to minimize locks. Unlocking in defer is not good
because lock is not released until the function returns. This is
sometimes bad when the function is called from inside it which leads to
a dead lock.