bugfixes and tests