-- ported from C++ to c
-- file name changed