added test for validation
fix some bugs