add memory gate