Index: binaries/data/mods/public/gui/session/input.js
===================================================================
--- binaries/data/mods/public/gui/session/input.js	(revision 14050)
+++ binaries/data/mods/public/gui/session/input.js	(working copy)
@@ -2108,7 +2108,7 @@
 	// Filter out all entities that can't go back to work.
 	var workers = g_Selection.toList().filter(function(e) {
 		var state = GetEntityState(e);
-		return (state && state.unitAI && state.unitAI.lastWorkOrder);
+		return (state && state.unitAI && state.unitAI.hasWorkOrders);
 	});
 	
 	Engine.PostNetworkCommand({"type": "back-to-work", "workers": workers});
Index: binaries/data/mods/public/gui/session/utility_functions.js
===================================================================
--- binaries/data/mods/public/gui/session/utility_functions.js	(revision 14050)
+++ binaries/data/mods/public/gui/session/utility_functions.js	(working copy)
@@ -294,7 +294,7 @@
 		});
 	}
 	
-	if (entState.unitAI && entState.unitAI.lastWorkOrder)
+	if (entState.unitAI && entState.unitAI.hasWorkOrders)
 	{
 		commands.push({
 		    "name": "back-to-work",
Index: binaries/data/mods/public/simulation/components/GuiInterface.js
===================================================================
--- binaries/data/mods/public/simulation/components/GuiInterface.js	(revision 14050)
+++ binaries/data/mods/public/simulation/components/GuiInterface.js	(working copy)
@@ -347,8 +347,8 @@
 	{
 		ret.unitAI = {
 			"state": cmpUnitAI.GetCurrentState(),
-			"orders": cmpUnitAI.GetOrders(),
-			"lastWorkOrder": cmpUnitAI.GetLastWorkOrder(),
+			"orders": cmpUnitAI.GetWorkOrders(),
+			"hasWorkOrders": cmpUnitAI.HasWorkOrders(),
 		};
 		// Add some information needed for ungarrisoning
 		if (cmpUnitAI.isGarrisoned && ret.player !== undefined)
Index: binaries/data/mods/public/simulation/components/Promotion.js
===================================================================
--- binaries/data/mods/public/simulation/components/Promotion.js	(revision 14050)
+++ binaries/data/mods/public/simulation/components/Promotion.js	(working copy)
@@ -78,8 +78,8 @@
 	cmpPromotedUnitAI.Cheer();
 	var orders = cmpCurrentUnitAI.GetOrders();
 	cmpPromotedUnitAI.AddOrders(orders);
-	var lastWorkOrder = cmpCurrentUnitAI.GetLastWorkOrder();
-	cmpPromotedUnitAI.SetLastWorkOrder(lastWorkOrder);
+	var workOrders = cmpCurrentUnitAI.GetWorkOrders();
+	cmpPromotedUnitAI.SetWorkOrders(workOrders);
 
 	Engine.BroadcastMessage(MT_EntityRenamed, { entity: this.entity, newentity: promotedUnitEntity });
 
Index: binaries/data/mods/public/simulation/components/UnitAI.js
===================================================================
--- binaries/data/mods/public/simulation/components/UnitAI.js	(revision 14050)
+++ binaries/data/mods/public/simulation/components/UnitAI.js	(working copy)
@@ -2526,8 +2526,8 @@
 	this.lastFormationName = "";
 	this.finishedOrder = false; // used to find if all formation members finished the order
 	
-	// To go back to work later
-	this.lastWorkOrder = undefined;
+	// Queue of remembered works
+	this.workOrders = [];
 
 	// For preventing increased action rate due to Stop orders or target death.
 	this.lastAttacked = undefined;
@@ -2804,17 +2804,6 @@
 	Engine.PostMessage(this.entity, MT_UnitAIStateChanged, { "to": state });
 };
 
-UnitAI.prototype.BackToWork = function()
-{
-	if(this.lastWorkOrder)
-	{
-		this.ReplaceOrder(this.lastWorkOrder.type, this.lastWorkOrder.data);
-		return true;
-	}
-	else
-		return false;
-};
-
 /**
  * Call when the current order has been completed (or failed).
  * Removes the current order from the queue, and processes the
@@ -2831,17 +2820,9 @@
 		error("FinishOrder called for entity " + this.entity + " (" + template + ") when order queue is empty\n" + stack);
 	}
 
-	// Remove the order from the queue, then forget it if it was a work to avoid trying to go back to it later.
+	// Remove the order from the queue
 	var finishedOrder = this.orderQueue.shift();
-	if(finishedOrder.type == "Gather" || finishedOrder.type == "Trade" || finishedOrder.type == "Repair")
-		this.lastWorkOrder = undefined;
-	
 	this.order = this.orderQueue[0];
-	// If the worker was returning a resource, we shall 
-	//	-> (if the worker is gathering) keep remembering the "Gather" order which is this.order
-	//	-> (if the worker was directly ordered to return a resource) forget the "ReturnResource" order which is finished
-	if(finishedOrder.type == "ReturnResource" && (!this.order || this.order.type != "Gather"))
-		this.lastWorkOrder = undefined;
 
 	if (this.orderQueue.length)
 	{
@@ -2892,9 +2873,6 @@
 {
 	var order = { "type": type, "data": data };
 	this.orderQueue.push(order);
-	
-	if(type == "Gather" || type == "Trade" || type == "Repair" || type == "ReturnResource")
-		this.lastWorkOrder = order;
 
 	// If we didn't already have an order, then process this new one
 	if (this.orderQueue.length == 1)
@@ -2952,6 +2930,28 @@
 
 UnitAI.prototype.ReplaceOrder = function(type, data)
 {
+	// Keep the previous orders if needed
+	if (data && data.force)
+	{
+		if (type == "Gather" || type == "Trade" || type == "Repair" || type == "ReturnResource")
+			this.workOrders = [];
+		else
+		{
+			var i0 = 0;
+			if (this.order && this.order.type == "Cheering")
+				i0 = 1;
+			for (var i = i0; i < this.orderQueue.length; ++i)
+			{
+				var ordertype = this.orderQueue[i].type;
+				if (ordertype == "Gather" || ordertype == "Trade" || ordertype == "Repair" || ordertype == "ReturnResource")
+				{
+					this.workOrders = this.orderQueue.slice(i);
+					break;
+				}
+			}
+		}
+	}
+
 	// Special cases of orders that shouldn't be replaced:
 	// 1. Cheering - we're invulnerable, add order after we finish
 	// 2. Packing/unpacking - we're immobile, add order after we finish (unless it's cancel)
@@ -2998,16 +2998,42 @@
 	return orders;
 };
 
-UnitAI.prototype.GetLastWorkOrder = function()
+UnitAI.prototype.BackToWork = function()
 {
-	return this.lastWorkOrder;
+	if(this.workOrders.length)
+	{
+		// Clear the order queue considering special orders not to avoid
+		if (this.order && this.order.type == "Cheering")
+		{
+			var cheeringOrder = this.orderQueue.shift();
+			this.orderQueue = [ cheeringOrder ];
+		}
+		else
+			this.orderQueue = [];
+		
+		this.AddOrders(this.workOrders);
+		this.workOrders = [];
+		return true;
+	}
+	else
+		return false;
 };
 
-UnitAI.prototype.SetLastWorkOrder = function(order)
+UnitAI.prototype.HasWorkOrders = function()
 {
-	this.lastWorkOrder = order;
+	return (this.workOrders.length > 0);
 };
 
+UnitAI.prototype.GetWorkOrders = function()
+{
+	return this.workOrders;
+};
+
+UnitAI.prototype.SetWorkOrders = function(orders)
+{
+	this.workOrders = orders;
+};
+
 UnitAI.prototype.TimerHandler = function(data, lateness)
 {
 	// Reset the timer
