use ffi as the c code interface

FFI extensions are easy to read, write and maintain