1330 1343 ccc refactoring

fixes #1330 and #1343. It is a joined pull-request for two others that I'll close.
@mcodescu ca you review this?