Replace transmute with as and as_mut_slice