Fixed issues around validation. Added more tests.