Factoring out some of the validation to isolate code.