better logging and a bug fix