Retraining memory: Theory and application