Miscs changes from CBPV branch

These are various refactorings I needed while working on the CBPV branch.