Work around using unsafe
Fix some crashes