more cleanup and fix logging bug