Add CDib and fix bugs in CDib