cleanup in c routines