Make typecasting an extensible hook instead of a hardcoded routine