Fix cleanup function