Speedups and bugfixes