review comments

1. release lock when in error
2. add some more comments in the code.