moving the validate functionality to a method