diff --git a/source/games/duke/src/actors_lava.cpp b/source/games/duke/src/actors_lava.cpp
index fcd338d51..1aef39f80 100644
--- a/source/games/duke/src/actors_lava.cpp
+++ b/source/games/duke/src/actors_lava.cpp
@@ -147,6 +147,12 @@ void addjaildoor(int p1, int p2, int iht, int jlt, int p3, int j)
 	if (jaildoorcnt >= 32)
 		I_Error("Too many jaildoor sectors");
 
+	if (jlt != 10 && jlt != 20 && jlt != 30 && jlt != 40)
+	{
+		Printf(PRINT_HIGH, "Bad direction %d for jail door with tag %d\n", iht);
+		return;	// wouldn't work so let's skip it.
+	}
+
 	jaildoordist[jaildoorcnt] = p1;
 	jaildoorspeed[jaildoorcnt] = p2;
 	jaildoorsecthtag[jaildoorcnt] = iht;
@@ -283,23 +289,21 @@ void dojaildoor(void)
 				endwall = startwall + sector[jaildoorsect[i]].wallnum;
 				for (j = startwall; j < endwall; j++)
 				{
+					x = wall[j].x;
+					y = wall[j].y;
 					switch (jaildoordir[i])
 					{
 						case 10:
-							x = wall[j].x;
-							y = wall[j].y + speed;
+							y += speed;
 							break;
 						case 20:
-							x = wall[j].x - speed;
-							y = wall[j].y;
+							x -= speed;
 							break;
 						case 30:
-							x = wall[j].x;
-							y = wall[j].y - speed;
+							y -= speed;
 							break;
 						case 40:
-							x = wall[j].x + speed;
-							y = wall[j].y;
+							x += speed;
 							break;
 					}
 					dragpoint(j,x,y);
diff --git a/source/games/duke/src/premap_r.cpp b/source/games/duke/src/premap_r.cpp
index 2844c615c..c436db2ce 100644
--- a/source/games/duke/src/premap_r.cpp
+++ b/source/games/duke/src/premap_r.cpp
@@ -513,7 +513,9 @@ void prelevel_r(int g)
 			{
 				if (sector[i].hitag == sector[j].hitag && j != i)
 				{
-					addjaildoor(dist, speed, sector[i].hitag, sector[j].lotag, sound, j);
+					// & 32767 to avoid some ordering issues here. 
+					// Other code assumes that the lotag is always a sector effector type and can mask the high bit in.
+					addjaildoor(dist, speed, sector[i].hitag, sector[j].lotag & 32767, sound, j);
 				}
 			}
 			break;