tests and various fixes