some rather big bugfixes & some performance improvement