tests and bug fixes