Added Amy's clean_memory code, which works with the tested values