bugfixes and performance improvements