more tests and bug fixes