         mainTypeSubstructure: [String: SourceKitRepresentable]
     ) -> [[String: SourceKitRepresentable]] {
         return file.structure.dictionary.substructure.filter { substructure in
+            guard let kind = substructure.kind else { return false }
             return substructure.bridge() != mainTypeSubstructure.bridge() &&
-                substructure.kind!.contains(SwiftDeclarationKind.extension.rawValue)
+                kind.contains(SwiftDeclarationKind.extension.rawValue)
         }
     }
 

        supportingTypeKinds.insert(SwiftDeclarationKind.protocol)

        return file.structure.dictionary.substructure.filter { substructure in
            guard let declarationKind = SwiftDeclarationKind(rawValue: substructure.kind!) else { return false }
            return substructure.bridge() != mainTypeSubstructure.bridge() &&
                supportingTypeKinds.contains(declarationKind)
        }

    private func mainTypeSubstructure(in dict: [String: SourceKitRepresentable]) -> [String: SourceKitRepresentable]? {
        let priorityKinds: [SwiftDeclarationKind] = [.class, .enum, .struct]
        let priorityKindRawValues = priorityKinds.map { $0.rawValue }

        let priorityKindSubstructures = dict.substructure.filter { substructure in
            guard let kind = substructure.kind else { return false }
            return priorityKindRawValues.contains(kind)
        }

        let substructuresSortedByBodyLength = priorityKindSubstructures.sorted { lhs, rhs in
            return (lhs.bodyLength ?? 0) > (rhs.bodyLength ?? 0)
        }

        guard let mainTypeSubstructure = substructuresSortedByBodyLength.first else {
            let substructuresSortedByBodyLength = dict.substructure.sorted { lhs, rhs in
                return (lhs.bodyLength ?? 0) > (rhs.bodyLength ?? 0)
            }

            // specify substructure with longest body as main type if existent
