 					if (debug)
 						trace('apply ' + (delta < 0 ? 'undo' : 'redo'), logEntry.id + ':', ObjectUtil.toString(diff));
 					
+					if (stepsRemaining == 0 && enableLogging.value)
+					{
+						// remember the session state right before applying the last step so we can rewrite the history if necessary
+						_prevState = WeaveAPI.SessionManager.getSessionState(_subject);
+					}
+					
 					if (combine)
 					{
 						baseDiff = WeaveAPI.SessionManager.combineDiff(baseDiff, diff);
-						if (stepsRemaining == 1)
+						if (stepsRemaining <= 1)
 						{
 							WeaveAPI.SessionManager.setSessionState(_subject, baseDiff, false);
 							combine = false;

				var combine:Boolean = stepsRemaining > 2;
				var baseDiff:Object = null;
				getCallbackCollection(_subject).delayCallbacks();
				while (stepsRemaining-- > 0)
				{
					if (delta < 0)

				
				_undoActive = delta < 0 && _savePending;
				_redoActive = delta > 0 && _savePending;
				if (!_savePending)
					_prevState = WeaveAPI.SessionManager.getSessionState(_subject);
				getCallbackCollection(this).triggerCallbacks();
			}
		}
