Added fixes to make it work the unsafe code.