Various CID fixes v3

Updated version of pull request #284:
- Use asserts as requested
- use Unlock() instead of put_unlock()
- add missing else block for store = NULL