Refactoring, cleanup of FFI