Various Bugfixes and Optimizations