move non-validation logic into separate function