New tests and bug fixes