performance improvements and bugfixes