Reverting to last working state (with memory leak)