lots of bugfixing