Bugfixes and (hopefully) optimizations.