removed ffi and used posix where possible