Bugfixes and speed enhancements