More refactoring

logging mostly works.