Refactored and centralized codemodel class/type referencing and error handling