several very big bugfixes