optimizations, bugfixes