diff --git a/Source/Core/General/Launcher.cs b/Source/Core/General/Launcher.cs
index 4568c5cdcfa7204418723d6ea6e8837a3d65451b..79703494542bb1d1d4fb6872bcaa712118ee4ea3 100644
--- a/Source/Core/General/Launcher.cs
+++ b/Source/Core/General/Launcher.cs
@@ -251,10 +251,6 @@ namespace CodeImp.DoomBuilder
 		public void TestAtSkill(int skill)
 		{
 			Cursor oldcursor = Cursor.Current;
-			ProcessStartInfo processinfo;
-			Process process;
-			TimeSpan deltatime;
-			string args;
 
 			// Check if configuration is OK
 			if(General.Map.ConfigSettings.TestProgram == "" || !File.Exists(General.Map.ConfigSettings.TestProgram))
@@ -299,10 +295,10 @@ namespace CodeImp.DoomBuilder
 				if(General.Map.Errors.Count == 0)
 				{
 					// Make arguments
-					args = ConvertParameters(General.Map.ConfigSettings.TestParameters, skill, General.Map.ConfigSettings.TestShortPaths);
+					string args = ConvertParameters(General.Map.ConfigSettings.TestParameters, skill, General.Map.ConfigSettings.TestShortPaths);
 
 					// Setup process info
-					processinfo = new ProcessStartInfo();
+					ProcessStartInfo processinfo = new ProcessStartInfo();
 					processinfo.Arguments = args;
 					processinfo.FileName = General.Map.ConfigSettings.TestProgram;
 					processinfo.CreateNoWindow = false;
@@ -321,7 +317,7 @@ namespace CodeImp.DoomBuilder
 					try
 					{
 						// Start the program
-						process = Process.Start(processinfo);
+						Process process = Process.Start(processinfo);
 
 						// Wait for program to complete
 						while(!process.WaitForExit(10))
@@ -330,7 +326,7 @@ namespace CodeImp.DoomBuilder
 						}
 
 						// Done
-						deltatime = TimeSpan.FromTicks(process.ExitTime.Ticks - process.StartTime.Ticks);
+						TimeSpan deltatime = TimeSpan.FromTicks(process.ExitTime.Ticks - process.StartTime.Ticks);
 						General.WriteLogLine("Test program has finished.");
 						General.WriteLogLine("Run time: " + deltatime.TotalSeconds.ToString("###########0.00") + " seconds");
 					}
diff --git a/Source/Core/Map/Linedef.cs b/Source/Core/Map/Linedef.cs
index 4f7101161b1aeca420e3289b3784377126339ab1..9bee55ec403c0379cacb65d681039f5726fefc0c 100644
--- a/Source/Core/Map/Linedef.cs
+++ b/Source/Core/Map/Linedef.cs
@@ -796,11 +796,10 @@ namespace CodeImp.DoomBuilder.Map
 		// Returns the new line resulting from the split, or null when it failed
 		public Linedef Split(Vertex v)
 		{
-			Linedef nl;
 			Sidedef nsd;
 
 			// Copy linedef and change vertices
-			nl = map.CreateLinedef(v, end);
+			Linedef nl = map.CreateLinedef(v, end);
 			if(nl == null) return null;
 			CopyPropertiesTo(nl);
 			SetEndVertex(v);
@@ -815,10 +814,6 @@ namespace CodeImp.DoomBuilder.Map
 				if(nsd == null) return null;
 				front.CopyPropertiesTo(nsd);
 				nsd.Marked = front.Marked;
-
-				// Make texture offset adjustments
-				if(!General.Map.UDMF) //mxd
-					nsd.OffsetX += (int)Vector2D.Distance(this.start.Position, this.end.Position);
 			}
 
 			// Copy back sidedef if exists
@@ -830,19 +825,24 @@ namespace CodeImp.DoomBuilder.Map
 				nsd.Marked = back.Marked;
 				
 				//mxd. Make texture offset adjustments
-				int distance = (int)Vector2D.Distance(nl.start.Position, nl.end.Position);
-				if(General.Map.UDMF) {
-					if (distance != 0)
-						back.SetUdmfTextureOffsetX(distance);
-				} else {
-					back.OffsetX += distance;
+				if((back.MiddleRequired() && back.LongMiddleTexture != MapSet.EmptyLongName) || back.HighRequired() || back.LowRequired()) {
+					int distance = (int) Vector2D.Distance(nl.start.Position, nl.end.Position);
+					if (General.Map.UDMF) {
+						if (distance != 0) back.SetUdmfTextureOffsetX(distance);
+					} else {
+						back.OffsetX += distance;
+					}
 				}
 			}
 
-			//mxd. Both sides of line are required, so we do it here...
-			if(nl.Front != null && General.Map.UDMF) {
+			//mxd. Make texture offset adjustments. Both sides of the new line are required, so we do it here...
+			if(nl.front != null && ((nl.front.MiddleRequired() || nl.front.LongMiddleTexture != MapSet.EmptyLongName) || nl.front.HighRequired() || nl.front.LowRequired())) {
 				int distance = (int)Vector2D.Distance(this.start.Position, this.end.Position);
-				if(distance != 0) nl.Front.SetUdmfTextureOffsetX(distance);
+				if(General.Map.UDMF) {
+					if(distance != 0) nl.front.SetUdmfTextureOffsetX(distance);
+				} else {
+					nl.front.OffsetX += distance;
+				}
 			}
 
 			// Return result
diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs
index 437b3bff46ccee2d5b6ecda6598f57af231a74eb..a6c374f06418f9aab76ab74db8876362843b8892 100644
--- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs
+++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs
@@ -3508,11 +3508,18 @@ namespace CodeImp.DoomBuilder.BuilderModes
 
 		//mxd. This converts offsetY from/to "normalized" offset for given lower wall
 		internal float GetBottomOffsetY(Sidedef side, float offset, float scaleY, bool fromNormalized) {
-			if(side.Line.IsFlagSet(General.Map.Config.LowerUnpeggedFlag) || side.Other == null || side.Other.Sector == null)
-				return offset;
-
-			//normalize offset
-			float surfaceHeight = (side.Sector.CeilHeight - side.Other.Sector.FloorHeight) * scaleY;
+			float surfaceHeight;
+			if (side.Line.IsFlagSet(General.Map.Config.LowerUnpeggedFlag)) {
+				if (side.Other == null || side.Other.Sector == null || side.Sector.CeilTexture != General.Map.Config.SkyFlatName ||
+				    side.Other.Sector.CeilTexture != General.Map.Config.SkyFlatName)
+					return offset;
+
+				//normalize offset the way Doom does it when front and back sector's ceiling is sky
+				surfaceHeight = (side.Sector.CeilHeight - side.Other.Sector.CeilHeight) * scaleY;
+			} else {
+				//normalize offset
+				surfaceHeight = (side.Sector.CeilHeight - side.Other.Sector.FloorHeight) * scaleY;
+			}
 
 			if(fromNormalized) return (float)Math.Round(offset + surfaceHeight);
 			return (float)Math.Round(offset - surfaceHeight);
diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualLower.cs b/Source/Plugins/BuilderModes/VisualModes/VisualLower.cs
index 85ef572442f10d80bd79146f677a9bf846515279..580fb5dcb1a4ece8344bee052f24f860d9173787 100644
--- a/Source/Plugins/BuilderModes/VisualModes/VisualLower.cs
+++ b/Source/Plugins/BuilderModes/VisualModes/VisualLower.cs
@@ -134,8 +134,13 @@ namespace CodeImp.DoomBuilder.BuilderModes
 			float floorbias = (Sidedef.Other.Sector.FloorHeight == Sidedef.Sector.FloorHeight) ? 1.0f : 0.0f;
 			if(Sidedef.Line.IsFlagSet(General.Map.Config.LowerUnpeggedFlag))
 			{
-				// When lower unpegged is set, the lower texture is bound to the bottom
-				tp.tlt.y = (float)Sidedef.Sector.CeilHeight - Sidedef.Other.Sector.FloorHeight;
+				if(Sidedef.Sector.CeilTexture == General.Map.Config.SkyFlatName && Sidedef.Other.Sector.CeilTexture == General.Map.Config.SkyFlatName) {
+					// mxd. Replicate Doom texture offset glitch when front and back sector's ceilings are sky
+					tp.tlt.y = (float)Sidedef.Other.Sector.CeilHeight - Sidedef.Other.Sector.FloorHeight;
+				} else {
+					// When lower unpegged is set, the lower texture is bound to the bottom
+					tp.tlt.y = (float) Sidedef.Sector.CeilHeight - Sidedef.Other.Sector.FloorHeight;
+				}
 			}
 			tp.trb.x = tp.tlt.x + Sidedef.Line.Length;
 			tp.trb.y = tp.tlt.y + (Sidedef.Other.Sector.FloorHeight - (Sidedef.Sector.FloorHeight + floorbias));