bugfixes and improved logging