some better logging and cleanup