Bugfixes and optimizations everywhere!