small fixes and cleanup of ffi