Update for Rust compiler

Remove old uneeded unsafe code, and clean up some test cases, more refactoring to come.