fix some ffi mistakes
add dead variable elimination