bugfixes and speedup