refactor some stuff and add more ffi bindings