some bugfixing and testcase fixes