subtle bugfixes, tests and examples