Remove unsafe code and use as for type conversions.