Bugfixes, new tests