bugfixes and error handling