tidy up validation logic into dedicate package