Moved from python to c