use unsafe cast + type check instead of safe cast