refactor and cleanup more cid stuff