Index: Include/Classes/System/DateTime.ab
===================================================================
--- Include/Classes/System/DateTime.ab	(revision 265)
+++ Include/Classes/System/DateTime.ab	(revision 268)
@@ -52,5 +52,5 @@
 
 	'Copy Constructor
-	Sub DateTime(ByRef dateTime As DateTime)
+	Sub DateTime(dateTime As DateTime)
 		This.m_Date = dateTime.m_Date
 	End Sub
@@ -59,25 +59,25 @@
 	End Sub
 
-	Function Operator + (ByRef value As TimeSpan) As DateTime
+	Function Operator + (value As TimeSpan) As DateTime
 		Return New DateTime(Ticks + value.Ticks)
 	End Function
 
-	Function Operator - (ByRef value As DateTime) As TimeSpan
+	Function Operator - (value As DateTime) As TimeSpan
 		Return TimeSpan.FromTicks(Ticks - value.Ticks)
 	End Function
 
-	Function Operator - (ByRef value As TimeSpan) As DateTime
+	Function Operator - (value As TimeSpan) As DateTime
 		Return New DateTime(Ticks - value.Ticks)
 	End Function
 
-	Function Operator == (ByRef value As DateTime) As Boolean
+	Function Operator == (value As DateTime) As Boolean
 		Return Equals(value)
 	End Function
 
-	Function Operator <> (ByRef value As DateTime) As Boolean
+	Function Operator <> (value As DateTime) As Boolean
 		Return Not Equals(value)
 	End Function
 
-	Function Operator > (ByRef value As DateTime) As Boolean
+	Function Operator > (value As DateTime) As Boolean
 		If DateTime.Compare(This, value) > 0 Then
 			Return True
@@ -87,5 +87,5 @@
 	End Function
 
-	Function Operator < (ByRef value As DateTime) As Boolean
+	Function Operator < (value As DateTime) As Boolean
 		If DateTime.Compare(This, value) < 0 Then
 			Return True
@@ -95,5 +95,5 @@
 	End Function
 
-	Function Operator >= (ByRef value As DateTime) As Boolean
+	Function Operator >= (value As DateTime) As Boolean
 		If DateTime.Compare(This, value) => 0 Then
 			Return True
@@ -103,5 +103,5 @@
 	End Function
 
-	Function Operator <= (ByRef value As DateTime) As Boolean
+	Function Operator <= (value As DateTime) As Boolean
 		If DateTime.Compare(This, value) <= 0 Then
 			Return True
@@ -191,9 +191,9 @@
 		
 	'Public Methods
-	Static Function Compare(ByRef t1 As DateTime, ByRef t2 As DateTime) As Int64
+	Static Function Compare(t1 As DateTime, t2 As DateTime) As Int64
 		Return t1.Ticks - t2.Ticks
 	End Function
 
-	Function Equals(ByRef value As DateTime) As Boolean
+	Function Equals(value As DateTime) As Boolean
 		If value.m_Date = m_Date Then
 			Return True
@@ -203,5 +203,5 @@
 	End Function
 
-	Static Function Equals(ByRef t1 As DateTime, ByRef t2 As DateTime) As Boolean
+	Static Function Equals(t1 As DateTime, t2 As DateTime) As Boolean
 		If t1.m_Date = t2.m_Date Then
 			Return True
@@ -215,5 +215,5 @@
 	End Function
 
-	Function Add(ByRef value As TimeSpan) As DateTime
+	Function Add(value As TimeSpan) As DateTime
 		Return This + value
 	End Function
@@ -259,10 +259,10 @@
 	End Function
 
-	Function Subtract(ByRef value As DateTime) As TimeSpan
-		Return New DateTime(This - value)
-	End Function
-
-	Function Subtract(ByRef value As TimeSpan) As DateTime
-		Return New DateTime(This - value)
+	Function Subtract(value As DateTime) As TimeSpan
+		Return This - value
+	End Function
+
+	Function Subtract(value As TimeSpan) As DateTime
+		Return This - value
 	End Function
 
Index: Include/Classes/System/Environment.ab
===================================================================
--- Include/Classes/System/Environment.ab	(revision 265)
+++ Include/Classes/System/Environment.ab	(revision 268)
@@ -3,4 +3,8 @@
 #require <api_psapi.sbp>
 #require <Classes/System/OperatingSystem.ab>
+#require <Classes/ActiveBasic/Windows/index.ab>
+
+Declare Function _System_SetEnvironmentVariable Lib "kernel32" Alias _FuncName_SetEnvironmentVariable (lpName As LPCTSTR, lpValue As LPTSTR) As BOOL
+Declare Function _System_GetEnvironmentVariable Lib "kernel32" Alias _FuncName_GetEnvironmentVariable (lpName As PCTSTR, lpBuffer As PTSTR, nSize As DWord) As DWord
 
 Namespace System
@@ -8,4 +12,6 @@
 Namespace Detail
 	TypeDef PFNGetProcessMemoryInfo = *Function(Process As HANDLE, ByRef mc As PROCESS_MEMORY_COUNTERS, cb As DWord) As BOOL
+
+	Dim hasShutdownStarted As Boolean
 End Namespace
 
@@ -48,5 +54,5 @@
 
 	Static Function HasShutdownStarted() As Boolean
-		Return False
+		Return Detail.hasShutdownStarted
 	End Function
 
@@ -59,5 +65,5 @@
 		End If
 		Return machineName
-	End Function			
+	End Function
 
 	Static Function NewLine() As String
@@ -92,5 +98,5 @@
 			sysDir = New String(p, len As Long)
 			_System_free(p)
-		End IF
+		End If
 		Return sysDir
 	End Function
@@ -112,5 +118,5 @@
 		End If
 		Return userName
-	End Function			
+	End Function
 
 	' Version
@@ -126,5 +132,4 @@
 			If pGetProcessMemoryInfo(GetCurrentProcess(), mc, Len (mc)) <> FALSE Then
 				WorkingSet = mc.WorkingSetSize
-				
 			End If
 		End If
@@ -154,5 +159,12 @@
 	' GetCommandLineArgs
 
-	' GetEnvironmentVariable
+	Static Function GetEnvironmentVariable(variable As String) As String
+		Dim tcsVariable = ToTCStr(variable)
+		Dim size = _System_GetEnvironmentVariable(tcsVariable, 0, 0)
+		Dim p = _System_malloc(SizeOf (TCHAR) * size) As PTSTR
+		Dim len = _System_GetEnvironmentVariable(tcsVariable, p, size)
+		GetEnvironmentVariable = New String(p, len As Long)
+		_System_free(p)
+	End Function
 
 	' GetEnvironmentVariables
@@ -169,5 +181,7 @@
 	' GetLogicalDrives
 
-	' SetEnvironmentVariable
+	Static Sub SetEnvironmentVariable(variable As String, value As String)
+		_System_SetEnvironmentVariable(ToTCStr(variable), ToTCStr(value))
+	End Sub
 
 Private
@@ -207,4 +221,3 @@
 End Enum
 
-
 End Namespace 'System
Index: Include/Classes/System/Math.ab
===================================================================
--- Include/Classes/System/Math.ab	(revision 265)
+++ Include/Classes/System/Math.ab	(revision 268)
@@ -1,6 +1,10 @@
 ' Classes/System/Math.ab
+
+#require <Classes/ActiveBasic/Math/Math.ab>
 
 #ifndef __SYSTEM_MATH_AB__
 #define __SYSTEM_MATH_AB__
+
+Namespace System
 
 Class Math
@@ -56,5 +60,5 @@
 	Static Function Acos(x As Double) As Double
 		If x < -1 Or x > 1 Then
-			Acos = _System_GetNaN()
+			Acos = ActiveBasic.Math.Detail.GetNaN()
 		Else
 			Acos = _System_HalfPI - Asin(x)
@@ -64,5 +68,5 @@
 	Static Function Asin(x As Double) As Double
 		If x < -1 Or x > 1 Then
-			Asin = _System_GetNaN()
+			Asin = ActiveBasic.Math.Detail.GetNaN()
 		Else
 			Asin = Math.Atan(x / Sqrt(1 - x * x))
@@ -71,9 +75,9 @@
 
 	Static Function Atan(x As Double) As Double
-		If IsNaN(x) Then
+		If ActiveBasic.Math.IsNaN(x) Then
 			Atan = x
 			Exit Function
-		ElseIf IsInf(x) Then
-			Atan = CopySign(_System_PI, x)
+		ElseIf ActiveBasic.Math.IsInf(x) Then
+			Atan = ActiveBasic.Math.CopySign(_System_PI, x)
 			Exit Function
 		End If
@@ -113,5 +117,5 @@
 			Atan2 = Atn(y / x)
 			If x < 0 Then
-				Atan2 += CopySign(_System_PI, y)
+				Atan2 += ActiveBasic.Math.CopySign(_System_PI, y)
 			End If
 		End If
@@ -131,8 +135,8 @@
 
 	Static Function Cos(x As Double) As Double
-		If IsNaN(x) Then
+		If ActiveBasic.Math.IsNaN(x) Then
 			Return x
-		ElseIf IsInf(x) Then
-			Return _System_GetNaN()
+		ElseIf ActiveBasic.Math.IsInf(x) Then
+			Return ActiveBasic.Math.Detail.GetNaN()
 		End If
 
@@ -159,7 +163,7 @@
 
 	Static Function Exp(x As Double) As Double
-		If IsNaN(x) Then
+		If ActiveBasic.Math.IsNaN(x) Then
 			Return x
-		Else If IsInf(x) Then
+		Else If ActiveBasic.Math.IsInf(x) Then
 			If 0 > x Then
 				Return 0
@@ -200,5 +204,5 @@
 
 	Static Function IEEERemainder(x As Double, y As Double) As Double
-		If y = 0 Then Return _System_GetNaN()
+		If y = 0 Then Return ActiveBasic.Math.Detail.GetNaN()
 		Dim q = x / y
 		If q <> Int(q) Then
@@ -224,8 +228,8 @@
 	Static Function Log(x As Double) As Double
 		If x = 0 Then
-			Log = _System_GetInf(True)
-		ElseIf x < 0 Or IsNaN(x) Then
-			Log = _System_GetNaN()
-		ElseIf IsInf(x) Then
+			Log = ActiveBasic.Math.Detail.GetInf(True)
+		ElseIf x < 0 Or ActiveBasic.Math.IsNaN(x) Then
+			Log = ActiveBasic.Math.Detail.GetNaN()
+		ElseIf ActiveBasic.Math.IsInf(x) Then
 			Log = x
 		Else
@@ -236,5 +240,5 @@
 			SetQWord(p, m + &h0010000000000000)
 			x /= tmp
-			Log = _System_LOG2 * k + _System_Log1p(x - 1)
+			Log = _System_LOG2 * k + ActiveBasic.Math.Detail.Log1p(x - 1)
 		End If
 	End Function
@@ -481,8 +485,8 @@
 
 	Static Function Sin(value As Double) As Double
-		If IsNaN(value) Then
+		If ActiveBasic.Math.IsNaN(value) Then
 			Return value
-		ElseIf IsInf(value) Then
-			Return _System_GetNaN()
+		ElseIf ActiveBasic.Math.IsInf(value) Then
+			Return ActiveBasic.Math.Detail.GetNaN()
 			Exit Function
 		End If
@@ -514,5 +518,5 @@
 		Dim i As *Word, j As Long, jj As Long, k As Long
 		If x > 0 Then
-			If IsInf(x) Then
+			If ActiveBasic.Math.IsInf(x) Then
 				Sqrt = x
 			Else
@@ -530,5 +534,5 @@
 			End If
 		ElseIf x < 0 Then
-			Sqrt = _System_GetNaN()
+			Sqrt = ActiveBasic.Math.Detail.GetNaN()
 		Else
 			'x = 0 Or NaN
@@ -538,9 +542,9 @@
 
 	Static Function Tan(x As Double) As Double
-		If IsNaN(x) Then
+		If ActiveBasic.Math.IsNaN(x) Then
 			Tan = x
 			Exit Function
-		ElseIf IsInf(x) Then
-			Tan = _System_GetNaN()
+		ElseIf ActiveBasic.Math.IsInf(x) Then
+			Tan = ActiveBasic.Math.Detail.GetNaN()
 			Exit Function
 		End If
@@ -554,5 +558,5 @@
 			Return -1 / t
 		Else
-			Return CopySign(_System_GetInf(FALSE), -t)
+			Return ActiveBasic.Math.CopySign(ActiveBasic.Math.Detail.GetInf(False), -t)
 		End If
 	End Function
@@ -599,4 +603,6 @@
 End Class
 
+End Namespace
+
 Const _System_HalfPI = (_System_PI * 0.5)
 Const _System_InverseHalfPI = (2 / _System_PI) '1 / (PI / 2)
@@ -604,4 +610,3 @@
 Const _System_InverseSqrt2 = 0.70710678118654752440084436210485 '1 / (√2)
 
-
 #endif '__SYSTEM_MATH_AB__
Index: Include/Classes/System/String.ab
===================================================================
--- Include/Classes/System/String.ab	(revision 265)
+++ Include/Classes/System/String.ab	(revision 268)
@@ -216,34 +216,23 @@
 		Sub ReSize(allocLength As Long)
 			If allocLength < 0 Then Exit Sub
-			If allocLength > m_Length Then
-				Dim oldLength As Long
-				oldLength = m_Length
-				If AllocStringBuffer(allocLength) <> 0 Then
+			Dim oldLength  = m_Length
+			If AllocStringBuffer(allocLength) <> 0 Then
+				If allocLength > oldLength Then
 					ZeroMemory(VarPtr(Chars[oldLength]), SizeOf (StrChar) * (m_Length - oldLength + 1))
+				Else
+					Chars[m_Length] = 0
 				End If
-			Else
-				m_Length = allocLength
+			End If
+		End Sub
+
+		Sub ReSize(allocLength As Long, c As StrChar)
+			If allocLength < 0 Then Exit Sub
+			Dim oldLength = m_Length
+			If AllocStringBuffer(allocLength) <> 0 Then
+				If allocLength > oldLength Then
+					_System_FillChar(VarPtr(Chars[oldLength]), (m_Length - oldLength) As SIZE_T, c)
+				End If
 				Chars[m_Length] = 0
 			End If
-		End Sub
-
-		Sub ReSize(allocLength As Long, c As StrChar)
-			If allocLength < 0 Then
-				Exit Sub
-			ElseIf allocLength > m_Length Then
-				Dim oldLength As Long
-				oldLength = m_Length
-				If AllocStringBuffer(allocLength) <> 0 Then
-					Dim p = VarPtr(Chars[oldLength]) As *StrChar
-					Dim fillLen = m_Length - oldLength
-					Dim i As Long
-					For i = 0 To ELM(fillLen)
-						p[i] = c
-					Next
-				End If
-			Else
-				m_Length = allocLength
-			End If
-			Chars[m_Length] = 0
 		End Sub
 
Index: Include/Classes/System/TimeSpan.ab
===================================================================
--- Include/Classes/System/TimeSpan.ab	(revision 265)
+++ Include/Classes/System/TimeSpan.ab	(revision 268)
@@ -20,5 +20,5 @@
 	End Sub
 
-	Sub TimeSpan(ByRef ts As TimeSpan)
+	Sub TimeSpan(ts As TimeSpan)
 		m_Time = ts.m_Time
 	End Sub
@@ -27,9 +27,9 @@
 	End Sub
 
-	Function Operator+ (ByRef ts As TimeSpan) As TimeSpan
+	Function Operator+ (ts As TimeSpan) As TimeSpan
 		Return FromTicks(m_Time + ts.m_Time)
 	End Function
 
-	Function Operator- (ByRef ts As TimeSpan) As TimeSpan
+	Function Operator- (ts As TimeSpan) As TimeSpan
 		Return FromTicks(m_Time - ts.m_Time)
 	End Function
@@ -43,13 +43,13 @@
 	End Function
 
-	Function Operator== (ByRef ts As TimeSpan) As Boolean
+	Function Operator== (ts As TimeSpan) As Boolean
 		Return Equals(ts)
 	End Function
 
-	Function Operator<> (ByRef ts As TimeSpan) As Boolean
+	Function Operator<> (ts As TimeSpan) As Boolean
 		Return Not Equals(ts)
 	End Function
 
-	Function Operator> (ByRef ts As TimeSpan) As Boolean
+	Function Operator> (ts As TimeSpan) As Boolean
 		If CompareTo(ts) > 0 Then
 			Return True
@@ -59,5 +59,5 @@
 	End Function
 
-	Function Operator< (ByRef ts As TimeSpan) As Boolean
+	Function Operator< (ts As TimeSpan) As Boolean
 		If CompareTo(ts) < 0 Then
 			Return True
@@ -67,5 +67,5 @@
 	End Function
 
-	Function Operator>= (ByRef ts As TimeSpan) As Boolean
+	Function Operator>= (ts As TimeSpan) As Boolean
 		If CompareTo(ts) => 0 Then
 			Return True
@@ -75,5 +75,5 @@
 	End Function
 
-	Function Operator<= (ByRef ts As TimeSpan) As Boolean
+	Function Operator<= (ts As TimeSpan) As Boolean
 		If CompareTo(ts) <= 0 Then
 			Return True
@@ -128,9 +128,9 @@
 	End Function
 
-	Function Add(ByRef ts As TimeSpan) As TimeSpan
+	Function Add(ts As TimeSpan) As TimeSpan
 		Return FromTicks(m_Time + ts.m_Time)
 	End Function
 
-	Static Function Compare(ByRef ts1 As TimeSpan, ByRef ts2 As TimeSpan) As Long
+	Static Function Compare(ts1 As TimeSpan, ts2 As TimeSpan) As Long
 		If ts1.m_Time < ts2.m_Time Then
 			Return -1
@@ -142,17 +142,17 @@
 	End Function
 
-	Function CompareTo(ByRef ts As TimeSpan) As Long
+	Function CompareTo(ts As TimeSpan) As Long
 		Return (m_Time - ts.m_Time) As Long
 	End Function
 
 	Function Duration() As TimeSpan
-		Return FromTicks(Math.Abs(m_Time))
-	End Function
-
-	Function Equals(ByRef ts As TimeSpan) As Boolean
+		Return FromTicks(System.Math.Abs(m_Time))
+	End Function
+
+	Function Equals(ts As TimeSpan) As Boolean
 		Return Equals(This, ts)
 	End Function
 
-	Static Function Equals(ByRef ts1 As TimeSpan, ByRef ts2 As TimeSpan) As Boolean
+	Static Function Equals(ts1 As TimeSpan, ts2 As TimeSpan) As Boolean
 		If ts1.m_Time = ts2.m_Time Then
 			Return True
@@ -195,5 +195,5 @@
 	End Function
 
-	Function Subtract(ByRef ts As TimeSpan) As TimeSpan
+	Function Subtract(ts As TimeSpan) As TimeSpan
 		Return FromTicks(m_Time - ts.m_Time)
 	End Function
