fixed CHS and memory leaks