some speed hacks and bugfixes