Unify cbr and cbz functions. Fix some bugs.