tests and various bugfixes