fixed the validation logic and fully tested code.