major bugfixes and tweaks