fix logging and cleanup