Fixups and unit tests