Move validation to its own method.