Refactored some validation and test-case.