doc
Refactor validation code