fixing logging and some handling of exceptions