added "extern C" stuff to avoid C++ name mungling