lots of preformance fixes and bugfixes