Fix cleanup pointer and added debug printf