Deduplicate validation code