Tests and bugfixes