various fixes and performance improvements