Bugfix and improved logging