reorganizing validation code