Continue to port code from C to Rust