Lot of bugfixes and performance improvements