Removed unnecessary using
Replace some casts with safe_cast
Use pin_ptr where possible