add clean memory function