more tests and defensive code