Add state claner and fix the problem about memory usage