Bugfixes, improved test