work in progress: tests and bugfixes