added some better logging and tests