refactored type_casting