updated the native code to work. TODO buffer sharing