move validation logic into it's own method