this code is repeated, would be nice to have a validator that does this for you