bugfixes and new tests