Additional tests and some bug fixes