fixed code using unmanaged FFI