Improved logging and minor bugfix