This also allows you to greatly simplify the validation code below.