fix cleanup function