Refactored dynamic type builder to avoid code duplication. Added general types for class redefinition and class rebasing.