bugfixes and asserts