Various CID fixes v2

Updated version of pull request #270

---
v2: removed commit #9f298e6 as requested