Made a few improvements the logging. In debug mode a debug.log is written.