Refactor duplicate code for struct_by_definition.
Refactor validate_definition to be less complex.