Prep 1.0.16.4
Prep 1.0.16.4

--- a/Documents/CHANGES.txt
+++ b/Documents/CHANGES.txt
@@ -1,3 +1,12 @@
+1.0.16.4, 01-05-2015
+    Fixed: Physically insignificant part mass is now accounted for.
+    Changed: Module mass accounted for as it now makes its way onto the launch pad (e.g. fairings).
+
+    Various optimisations:
+        Object pooling.
+        Removed LINQ expressions.
+        Converted foreach to for loops.
+
 1.0.16.3, 27-04-2015
     Fixed issue with the toolbar icons not being created.
     Removed superfluous 'm/s' on the mach slider in the build engineer.

--- a/KerbalEngineer/Editor/BuildAdvanced.cs
+++ b/KerbalEngineer/Editor/BuildAdvanced.cs
@@ -20,9 +20,7 @@
 namespace KerbalEngineer.Editor
 {
     #region Using Directives
-
     using System;
-    using System.Linq;
     using Extensions;
     using Flight;
     using Helpers;
@@ -54,6 +52,7 @@
         private bool hasChanged;
         private GUIStyle infoStyle;
         private bool isEditorLocked;
+        private float maxMach;
         private int numberOfStages;
         private Rect position = new Rect(265.0f, 45.0f, 0, 0);
         private GUIStyle settingAtmoStyle;
@@ -65,12 +64,9 @@
         private GUIStyle titleStyle;
         private bool visible = true;
         private GUIStyle windowStyle;
-        private float maxMach;
-
         #endregion
 
         #region Properties
-
         /// <summary>
         ///     Gets the current instance if started or returns null.
         /// </summary>
@@ -81,8 +77,14 @@
         /// </summary>
         public bool CompactMode
         {
-            get { return this.compactMode; }
-            set { this.compactMode = value; }
+            get
+            {
+                return compactMode;
+            }
+            set
+            {
+                compactMode = value;
+            }
         }
 
         /// <summary>
@@ -90,8 +92,14 @@
         /// </summary>
         public bool ShowAllStages
         {
-            get { return this.showAllStages; }
-            set { this.showAllStages = value; }
+            get
+            {
+                return showAllStages;
+            }
+            set
+            {
+                showAllStages = value;
+            }
         }
 
         /// <summary>
@@ -99,8 +107,14 @@
         /// </summary>
         public bool ShowAtmosphericDetails
         {
-            get { return this.showAtmosphericDetails; }
-            set { this.showAtmosphericDetails = value; }
+            get
+            {
+                return showAtmosphericDetails;
+            }
+            set
+            {
+                showAtmosphericDetails = value;
+            }
         }
 
         /// <summary>
@@ -108,8 +122,14 @@
         /// </summary>
         public bool ShowSettings
         {
-            get { return this.showSettings; }
-            set { this.showSettings = value; }
+            get
+            {
+                return showSettings;
+            }
+            set
+            {
+                showSettings = value;
+            }
         }
 
         /// <summary>
@@ -117,26 +137,36 @@
         /// </summary>
         public bool Visible
         {
-            get { return this.visible; }
-            set { this.visible = value; }
-        }
-
+            get
+            {
+                return visible;
+            }
+            set
+            {
+                visible = value;
+            }
+        }
         #endregion
 
         #region Methods
+        private static Rect compactModeRect = new Rect(0.0f, 5.0f, 0.0f, 20.0f);
+        private static Stage stage;
+        private static int stagesCount;
+        private static int stagesLength;
+        private static string title;
 
         protected void Awake()
         {
             try
             {
                 Instance = this;
-                this.bodiesList = this.gameObject.AddComponent<DropDown>();
-                this.bodiesList.DrawCallback = this.DrawBodiesList;
-                this.Load();
+                bodiesList = gameObject.AddComponent<DropDown>();
+                bodiesList.DrawCallback = DrawBodiesList;
+                Load();
 
                 SimManager.UpdateModSettings();
-                SimManager.OnReady -= this.GetStageInfo;
-                SimManager.OnReady += this.GetStageInfo;
+                SimManager.OnReady -= GetStageInfo;
+                SimManager.OnReady += GetStageInfo;
             }
             catch (Exception ex)
             {
@@ -151,18 +181,18 @@
         {
             try
             {
-                var handler = new SettingHandler();
-                handler.Set("visible", this.visible);
-                handler.Set("windowPositionX", this.position.x);
-                handler.Set("windowPositionY", this.position.y);
-                handler.Set("compactMode", this.compactMode);
-                handler.Set("compactCollapseRight", this.compactCollapseRight);
-                handler.Set("showAllStages", this.showAllStages);
-                handler.Set("showAtmosphericDetails", this.showAtmosphericDetails);
-                handler.Set("showSettings", this.showSettings);
+                SettingHandler handler = new SettingHandler();
+                handler.Set("visible", visible);
+                handler.Set("windowPositionX", position.x);
+                handler.Set("windowPositionY", position.y);
+                handler.Set("compactMode", compactMode);
+                handler.Set("compactCollapseRight", compactCollapseRight);
+                handler.Set("showAllStages", showAllStages);
+                handler.Set("showAtmosphericDetails", showAtmosphericDetails);
+                handler.Set("showSettings", showSettings);
                 handler.Set("selectedBodyName", CelestialBodies.SelectedBody.Name);
                 handler.Save("BuildAdvanced.xml");
-                GuiDisplaySize.OnSizeChanged -= this.OnSizeChanged;
+                GuiDisplaySize.OnSizeChanged -= OnSizeChanged;
             }
             catch (Exception ex)
             {
@@ -174,45 +204,61 @@
         {
             try
             {
-                if (!this.visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0 || EditorLogic.fetch.editorScreen != EditorScreen.Parts)
+                if (!visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0 || EditorLogic.fetch.editorScreen != EditorScreen.Parts)
                 {
                     return;
                 }
 
-                if (this.stages == null)
+                if (stages == null)
                 {
                     return;
                 }
 
                 // Change the window title based on whether in compact mode or not.
-                var title = !this.compactMode ? "KERBAL ENGINEER REDUX " + EngineerGlobals.AssemblyVersion : "K.E.R. " + EngineerGlobals.AssemblyVersion + (this.showAtmosphericDetails ? " (ATMOS.)" : String.Empty);
+                title = !compactMode ? "KERBAL ENGINEER REDUX " + EngineerGlobals.AssemblyVersion : "K.E.R. " + EngineerGlobals.AssemblyVersion + (showAtmosphericDetails ? " (ATMOS.)" : String.Empty);
 
                 // Reset the window size when the staging or something else has changed.
-                var stageCount = this.stages.Count(stage => this.showAllStages || stage.deltaV > 0);
-                if (this.hasChanged || stageCount != this.numberOfStages)
-                {
-                    this.hasChanged = false;
-                    this.numberOfStages = stageCount;
-
-                    this.position.width = 0;
-                    this.position.height = 0;
+                stagesLength = stages.Length;
+                if (showAllStages)
+                {
+                    stagesCount = stagesLength;
+                }
+                if (showAllStages == false)
+                {
+                    stagesCount = 0;
+                    for (int i = 0; i < stagesLength; ++i)
+                    {
+                        if (stages[i].deltaV > 0.0f)
+                        {
+                            stagesCount = stagesCount + 1;
+                        }
+                    }
+                }
+
+                if (hasChanged || stagesCount != numberOfStages)
+                {
+                    hasChanged = false;
+                    numberOfStages = stagesCount;
+
+                    position.width = 0;
+                    position.height = 0;
                 }
 
                 GUI.skin = null;
-                this.position = GUILayout.Window(this.GetInstanceID(), this.position, this.Window, title, this.windowStyle).ClampToScreen();
-
-                if (this.compactCheck > 0 && this.compactCollapseRight)
-                {
-                    this.position.x = this.compactRight - this.position.width;
-                    this.compactCheck--;
-                }
-                else if (this.compactCheck > 0)
-                {
-                    this.compactCheck = 0;
+                position = GUILayout.Window(GetInstanceID(), position, Window, title, windowStyle).ClampToScreen();
+
+                if (compactCheck > 0 && compactCollapseRight)
+                {
+                    position.x = compactRight - position.width;
+                    compactCheck--;
+                }
+                else if (compactCheck > 0)
+                {
+                    compactCheck = 0;
                 }
 
                 // Check editor lock to manage click-through.
-                this.CheckEditorLock();
+                CheckEditorLock();
             }
             catch (Exception ex)
             {
@@ -224,8 +270,8 @@
         {
             try
             {
-                this.InitialiseStyles();
-                GuiDisplaySize.OnSizeChanged += this.OnSizeChanged;
+                InitialiseStyles();
+                GuiDisplaySize.OnSizeChanged += OnSizeChanged;
             }
             catch (Exception ex)
             {
@@ -239,23 +285,23 @@
             {
                 if (Input.GetKeyDown(KeyBinder.EditorShowHide))
                 {
-                    this.visible = !this.visible;
-                    if (!this.visible)
+                    visible = !visible;
+                    if (!visible)
                     {
-                        this.EditorLock(false);
+                        EditorLock(false);
                     }
                 }
 
-                if (!this.visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0)
-                {
-                    this.bodiesList.enabled = false;
+                if (!visible || EditorLogic.fetch == null || EditorLogic.fetch.ship.parts.Count == 0)
+                {
+                    bodiesList.enabled = false;
                     return;
                 }
 
                 // Configure the simulation parameters based on the selected reference body.
                 SimManager.Gravity = CelestialBodies.SelectedBody.Gravity;
 
-                if (this.showAtmosphericDetails)
+                if (showAtmosphericDetails)
                 {
                     SimManager.Atmosphere = CelestialBodies.SelectedBody.GetAtmospheres(Altitude);
                 }
@@ -264,7 +310,7 @@
                     SimManager.Atmosphere = 0;
                 }
 
-                SimManager.Mach = this.atmosphericMach;
+                SimManager.Mach = atmosphericMach;
 
                 SimManager.RequestSimulation();
                 SimManager.TryStartSimulation();
@@ -280,13 +326,13 @@
         /// </summary>
         private void CheckEditorLock()
         {
-            if ((this.position.MouseIsOver() || this.bodiesList.Position.MouseIsOver()) && !this.isEditorLocked)
-            {
-                this.EditorLock(true);
-            }
-            else if (!this.position.MouseIsOver() && !this.bodiesList.Position.MouseIsOver() && this.isEditorLocked)
-            {
-                this.EditorLock(false);
+            if ((position.MouseIsOver() || bodiesList.Position.MouseIsOver()) && !isEditorLocked)
+            {
+                EditorLock(true);
+            }
+            else if (!position.MouseIsOver() && !bodiesList.Position.MouseIsOver() && isEditorLocked)
+            {
+                EditorLock(false);
             }
         }
 
@@ -299,7 +345,7 @@
             {
                 GUILayout.BeginHorizontal();
                 GUILayout.BeginVertical();
-                GUILayout.Label("Altitude: " + (Altitude * 0.001f).ToString("F1") + "km", this.settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset));
+                GUILayout.Label("Altitude: " + (Altitude * 0.001f).ToString("F1") + "km", settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset));
                 GUI.skin = HighLogic.Skin;
                 Altitude = GUILayout.HorizontalSlider(Altitude, 0.0f, (float)(CelestialBodies.SelectedBody.CelestialBody.atmosphereDepth));
                 GUI.skin = null;
@@ -308,7 +354,7 @@
                 GUILayout.Space(5.0f);
 
                 GUILayout.BeginVertical();
-                GUILayout.Label("Mach: " + this.atmosphericMach.ToString("F1"), this.settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset));
+                GUILayout.Label("Mach: " + atmosphericMach.ToString("F1"), settingAtmoStyle, GUILayout.Width(125.0f * GuiDisplaySize.Offset));
                 GUI.skin = HighLogic.Skin;
                 atmosphericMach = GUILayout.HorizontalSlider(Mathf.Clamp(atmosphericMach, 0.0f, maxMach), 0.0f, maxMach);
                 GUI.skin = null;
@@ -325,13 +371,13 @@
         {
             if (CelestialBodies.SystemBody == CelestialBodies.SelectedBody)
             {
-                this.DrawBody(CelestialBodies.SystemBody);
+                DrawBody(CelestialBodies.SystemBody);
             }
             else
             {
-                foreach (var body in CelestialBodies.SystemBody.Children)
-                {
-                    this.DrawBody(body);
+                foreach (CelestialBodies.BodyInfo body in CelestialBodies.SystemBody.Children)
+                {
+                    DrawBody(body);
                 }
             }
         }
@@ -340,19 +386,19 @@
         {
             GUILayout.BeginHorizontal();
             GUILayout.Space(20.0f * depth);
-            if (GUILayout.Button(bodyInfo.Children.Count > 0 ? bodyInfo.Name + " [" + bodyInfo.Children.Count + "]" : bodyInfo.Name, bodyInfo.Selected && bodyInfo.SelectedDepth == 0 ? this.bodiesButtonActiveStyle : this.bodiesButtonStyle))
+            if (GUILayout.Button(bodyInfo.Children.Count > 0 ? bodyInfo.Name + " [" + bodyInfo.Children.Count + "]" : bodyInfo.Name, bodyInfo.Selected && bodyInfo.SelectedDepth == 0 ? bodiesButtonActiveStyle : bodiesButtonStyle))
             {
                 CelestialBodies.SetSelectedBody(bodyInfo.Name);
                 Altitude = 0.0f;
-                this.bodiesList.Resize = true;
+                bodiesList.Resize = true;
             }
             GUILayout.EndHorizontal();
 
             if (bodyInfo.Selected)
             {
-                foreach (var body in bodyInfo.Children)
-                {
-                    this.DrawBody(body, depth + 1);
+                for (int i = 0; i < bodyInfo.Children.Count; ++i)
+                {
+                    DrawBody(bodyInfo.Children[i], depth + 1);
                 }
             }
         }
@@ -363,12 +409,13 @@
         private void DrawBurnTime()
         {
             GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset));
-            GUILayout.Label("BURN", this.titleStyle);
-            foreach (var stage in this.stages)
-            {
-                if (this.showAllStages || stage.deltaV > 0)
-                {
-                    GUILayout.Label(TimeFormatter.ConvertToString(stage.time), this.infoStyle);
+            GUILayout.Label("BURN", titleStyle);
+            for (int i = 0; i < stagesLength; ++i)
+            {
+                stage = stages[i];
+                if (showAllStages || stage.deltaV > 0.0)
+                {
+                    GUILayout.Label(TimeFormatter.ConvertToString(stage.time), infoStyle);
                 }
             }
             GUILayout.EndVertical();
@@ -380,12 +427,13 @@
         private void DrawCost()
         {
             GUILayout.BeginVertical(GUILayout.Width(110.0f * GuiDisplaySize.Offset));
-            GUILayout.Label("COST", this.titleStyle);
-            foreach (var stage in this.stages)
-            {
-                if (this.showAllStages || stage.deltaV > 0)
-                {
-                    GUILayout.Label(Units.Cost(stage.cost, stage.totalCost), this.infoStyle);
+            GUILayout.Label("COST", titleStyle);
+            for (int i = 0; i < stagesLength; ++i)
+            {
+                stage = stages[i];
+                if (showAllStages || stage.deltaV > 0.0)
+                {
+                    GUILayout.Label(Units.Cost(stage.cost, stage.totalCost), infoStyle);
                 }
             }
             GUILayout.EndVertical();
@@ -397,12 +445,13 @@
         private void DrawDeltaV()
         {
             GUILayout.BeginVertical(GUILayout.Width(100.0f * GuiDisplaySize.Offset));
-            GUILayout.Label("DELTA-V", this.titleStyle);
-            foreach (var stage in this.stages)
-            {
-                if (this.showAllStages || stage.deltaV > 0)
-                {
-                    GUILayout.Label(stage.deltaV.ToString("N0") + " / " + stage.inverseTotalDeltaV.ToString("N0") + "m/s", this.infoStyle);
+            GUILayout.Label("DELTA-V", titleStyle);
+            for (int i = 0; i < stagesLength; ++i)
+            {
+                stage = stages[i];
+                if (showAllStages || stage.deltaV > 0.0)
+                {
+                    GUILayout.Label(stage.deltaV.ToString("N0") + " / " + stage.inverseTotalDeltaV.ToString("N0") + "m/s", infoStyle);
                 }
             }
             GUILayout.EndVertical();
@@ -414,12 +463,13 @@
         private void DrawIsp()
         {
             GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset));
-            GUILayout.Label("ISP", this.titleStyle);
-            foreach (var stage in this.stages)
-            {
-                if (this.showAllStages || stage.deltaV > 0)
-                {
-                    GUILayout.Label(stage.isp.ToString("F1") + "s", this.infoStyle);
+            GUILayout.Label("ISP", titleStyle);
+            for (int i = 0; i < stagesLength; ++i)
+            {
+                stage = stages[i];
+                if (showAllStages || stage.deltaV > 0.0)
+                {
+                    GUILayout.Label(stage.isp.ToString("F1") + "s", infoStyle);
                 }
             }
             GUILayout.EndVertical();
@@ -431,12 +481,13 @@
         private void DrawMass()
         {
             GUILayout.BeginVertical(GUILayout.Width(110.0f * GuiDisplaySize.Offset));
-            GUILayout.Label("MASS", this.titleStyle);
-            foreach (var stage in this.stages)
-            {
-                if (this.showAllStages || stage.deltaV > 0)
-                {
-                    GUILayout.Label(Units.ToMass(stage.mass, stage.totalMass), this.infoStyle);
+            GUILayout.Label("MASS", titleStyle);
+            for (int i = 0; i < stagesLength; ++i)
+            {
+                stage = stages[i];
+                if (showAllStages || stage.deltaV > 0.0)
+                {
+                    GUILayout.Label(Units.ToMass(stage.mass, stage.totalMass), infoStyle);
                 }
             }
             GUILayout.EndVertical();
@@ -448,12 +499,13 @@
         private void DrawPartCount()
         {
             GUILayout.BeginVertical(GUILayout.Width(50.0f * GuiDisplaySize.Offset));
-            GUILayout.Label("PARTS", this.titleStyle);
-            foreach (var stage in this.stages)
-            {
-                if (this.showAllStages || stage.deltaV > 0)
-                {
-                    GUILayout.Label(stage.partCount + " / " + stage.totalPartCount, this.infoStyle);
+            GUILayout.Label("PARTS", titleStyle);
+            for (int i = 0; i < stagesLength; ++i)
+            {
+                stage = stages[i];
+                if (showAllStages || stage.deltaV > 0.0)
+                {
+                    GUILayout.Label(stage.partCount + " / " + stage.totalPartCount, infoStyle);
                 }
             }
             GUILayout.EndVertical();
@@ -465,48 +517,48 @@
         private void DrawSettings()
         {
             GUILayout.BeginHorizontal();
-            GUILayout.Label("Compact mode collapses to the:", this.settingStyle);
-            this.compactCollapseRight = !GUILayout.Toggle(!this.compactCollapseRight, "LEFT", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
-            this.compactCollapseRight = GUILayout.Toggle(this.compactCollapseRight, "RIGHT", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
+            GUILayout.Label("Compact mode collapses to the:", settingStyle);
+            compactCollapseRight = !GUILayout.Toggle(!compactCollapseRight, "LEFT", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
+            compactCollapseRight = GUILayout.Toggle(compactCollapseRight, "RIGHT", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
             GUILayout.EndHorizontal();
 
             GUILayout.BeginHorizontal();
             GUILayout.Label("Simulate using vectored thrust values:");
-            SimManager.vectoredThrust = GUILayout.Toggle(SimManager.vectoredThrust, "ENABLED", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
+            SimManager.vectoredThrust = GUILayout.Toggle(SimManager.vectoredThrust, "ENABLED", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
             GUILayout.EndHorizontal();
 
             GUILayout.BeginHorizontal();
-            GUILayout.Label("Build Engineer Overlay:", this.settingStyle);
-            BuildOverlay.Visible = GUILayout.Toggle(BuildOverlay.Visible, "VISIBLE", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
-            BuildOverlayPartInfo.NamesOnly = GUILayout.Toggle(BuildOverlayPartInfo.NamesOnly, "NAMES ONLY", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
-            BuildOverlayPartInfo.ClickToOpen = GUILayout.Toggle(BuildOverlayPartInfo.ClickToOpen, "CLICK TO OPEN", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
+            GUILayout.Label("Build Engineer Overlay:", settingStyle);
+            BuildOverlay.Visible = GUILayout.Toggle(BuildOverlay.Visible, "VISIBLE", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
+            BuildOverlayPartInfo.NamesOnly = GUILayout.Toggle(BuildOverlayPartInfo.NamesOnly, "NAMES ONLY", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
+            BuildOverlayPartInfo.ClickToOpen = GUILayout.Toggle(BuildOverlayPartInfo.ClickToOpen, "CLICK TO OPEN", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
             GUILayout.EndHorizontal();
 
             GUILayout.BeginHorizontal();
-            GUILayout.Label("Flight Engineer activation mode:", this.settingStyle);
-            FlightEngineerCore.IsCareerMode = GUILayout.Toggle(FlightEngineerCore.IsCareerMode, "CAREER", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
-            FlightEngineerCore.IsCareerMode = !GUILayout.Toggle(!FlightEngineerCore.IsCareerMode, "PARTLESS", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
+            GUILayout.Label("Flight Engineer activation mode:", settingStyle);
+            FlightEngineerCore.IsCareerMode = GUILayout.Toggle(FlightEngineerCore.IsCareerMode, "CAREER", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
+            FlightEngineerCore.IsCareerMode = !GUILayout.Toggle(!FlightEngineerCore.IsCareerMode, "PARTLESS", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
             GUILayout.EndHorizontal();
 
             GUILayout.BeginHorizontal();
-            GUILayout.Label("Flight Engineer Career Limitations:", this.settingStyle);
-            FlightEngineerCore.IsKerbalLimited = GUILayout.Toggle(FlightEngineerCore.IsKerbalLimited, "KERBAL", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
-            FlightEngineerCore.IsTrackingStationLimited = GUILayout.Toggle(FlightEngineerCore.IsTrackingStationLimited, "TRACKING", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
+            GUILayout.Label("Flight Engineer Career Limitations:", settingStyle);
+            FlightEngineerCore.IsKerbalLimited = GUILayout.Toggle(FlightEngineerCore.IsKerbalLimited, "KERBAL", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
+            FlightEngineerCore.IsTrackingStationLimited = GUILayout.Toggle(FlightEngineerCore.IsTrackingStationLimited, "TRACKING", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset));
             GUILayout.EndHorizontal();
 
             GUILayout.BeginHorizontal();
-            GUILayout.Label("GUI Size: " + GuiDisplaySize.Increment, this.settingStyle);
-            if (GUILayout.Button("<", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)))
+            GUILayout.Label("GUI Size: " + GuiDisplaySize.Increment, settingStyle);
+            if (GUILayout.Button("<", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)))
             {
                 GuiDisplaySize.Increment--;
             }
-            if (GUILayout.Button(">", this.buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)))
+            if (GUILayout.Button(">", buttonStyle, GUILayout.Width(100.0f * GuiDisplaySize.Offset)))
             {
                 GuiDisplaySize.Increment++;
             }
             GUILayout.EndHorizontal();
 
-            GUILayout.Label("Minimum delay between simulations: " + SimManager.minSimTime.Milliseconds + "ms", this.settingStyle);
+            GUILayout.Label("Minimum delay between simulations: " + SimManager.minSimTime.Milliseconds + "ms", settingStyle);
             GUI.skin = HighLogic.Skin;
             SimManager.minSimTime = new TimeSpan(0, 0, 0, 0, (int)GUILayout.HorizontalSlider(SimManager.minSimTime.Milliseconds, 0, 2000.0f));
             GUI.skin = null;
@@ -518,12 +570,13 @@
         private void DrawStageNumbers()
         {
             GUILayout.BeginVertical(GUILayout.Width(30.0f * GuiDisplaySize.Offset));
-            GUILayout.Label(string.Empty, this.titleStyle);
-            foreach (var stage in this.stages)
-            {
-                if (this.showAllStages || stage.deltaV > 0)
-                {
-                    GUILayout.Label("S" + stage.number, this.titleStyle);
+            GUILayout.Label(string.Empty, titleStyle);
+            for (int i = 0; i < stagesLength; ++i)
+            {
+                stage = stages[i];
+                if (showAllStages || stage.deltaV > 0.0)
+                {
+                    GUILayout.Label("S" + stage.number, titleStyle);
                 }
             }
             GUILayout.EndVertical();
@@ -535,12 +588,13 @@
         private void DrawThrust()
         {
             GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset));
-            GUILayout.Label("THRUST", this.titleStyle);
-            foreach (var stage in this.stages)
-            {
-                if (this.showAllStages || stage.deltaV > 0)
-                {
-                    GUILayout.Label(stage.thrust.ToForce(), this.infoStyle);
+            GUILayout.Label("THRUST", titleStyle);
+            for (int i = 0; i < stagesLength; ++i)
+            {
+                stage = stages[i];
+                if (showAllStages || stage.deltaV > 0.0)
+                {
+                    GUILayout.Label(stage.thrust.ToForce(), infoStyle);
                 }
             }
             GUILayout.EndVertical();
@@ -552,12 +606,13 @@
         private void DrawTorque()
         {
             GUILayout.BeginVertical(GUILayout.Width(75.0f * GuiDisplaySize.Offset));
-            GUILayout.Label("TORQUE", this.titleStyle);
-            foreach (var stage in this.stages)
-            {
-                if (this.showAllStages || stage.deltaV > 0)
-                {
-                    GUILayout.Label(stage.maxThrustTorque.ToTorque(), this.infoStyle);
+            GUILayout.Label("TORQUE", titleStyle);
+            for (int i = 0; i < stagesLength; ++i)
+            {
+                stage = stages[i];
+                if (showAllStages || stage.deltaV > 0.0)
+                {
+                    GUILayout.Label(stage.maxThrustTorque.ToTorque(), infoStyle);
                 }
             }
             GUILayout.EndVertical();
@@ -569,12 +624,13 @@
         private void DrawTwr()
         {
             GUILayout.BeginVertical(GUILayout.Width(100.0f * GuiDisplaySize.Offset));
-            GUILayout.Label("TWR (MAX)", this.titleStyle);
-            foreach (var stage in this.stages)
-            {
-                if (this.showAllStages || stage.deltaV > 0)
-                {
-                    GUILayout.Label(stage.thrustToWeight.ToString("F2") + " (" + stage.maxThrustToWeight.ToString("F2") + ")", this.infoStyle);
+            GUILayout.Label("TWR (MAX)", titleStyle);
+            for (int i = 0; i < stagesLength; ++i)
+            {
+                stage = stages[i];
+                if (showAllStages || stage.deltaV > 0.0)
+                {
+                    GUILayout.Label(stage.thrustToWeight.ToString("F2") + " (" + stage.maxThrustToWeight.ToString("F2") + ")", infoStyle);
                 }
             }
             GUILayout.EndVertical();
@@ -586,13 +642,13 @@
             {
                 EditorLogic.fetch.Lock(true, true, true, "KER_BuildAdvanced");
                 BuildOverlayPartInfo.Hidden = true;
-                this.isEditorLocked = true;
+                isEditorLocked = true;
             }
             else
             {
                 EditorLogic.fetch.Unlock("KER_BuildAdvanced");
                 BuildOverlayPartInfo.Hidden = false;
-                this.isEditorLocked = false;
+                isEditorLocked = false;
             }
         }
 
@@ -610,22 +666,22 @@
         /// </summary>
         private void InitialiseStyles()
         {
-            this.windowStyle = new GUIStyle(HighLogic.Skin.window)
+            windowStyle = new GUIStyle(HighLogic.Skin.window)
             {
                 alignment = TextAnchor.UpperLeft
             };
 
-            this.areaStyle = new GUIStyle(HighLogic.Skin.box)
+            areaStyle = new GUIStyle(HighLogic.Skin.box)
             {
                 padding = new RectOffset(0, 0, 9, 0)
             };
 
-            this.areaSettingStyle = new GUIStyle(HighLogic.Skin.box)
+            areaSettingStyle = new GUIStyle(HighLogic.Skin.box)
             {
                 padding = new RectOffset(10, 10, 10, 10)
             };
 
-            this.buttonStyle = new GUIStyle(HighLogic.Skin.button)
+            buttonStyle = new GUIStyle(HighLogic.Skin.button)
             {
                 normal =
                 {
@@ -636,7 +692,7 @@
                 alignment = TextAnchor.MiddleCenter
             };
 
-            this.titleStyle = new GUIStyle(HighLogic.Skin.label)
+            titleStyle = new GUIStyle(HighLogic.Skin.label)
             {
                 normal =
                 {
@@ -648,7 +704,7 @@
                 stretchWidth = true,
             };
 
-            this.infoStyle = new GUIStyle(HighLogic.Skin.label)
+            infoStyle = new GUIStyle(HighLogic.Skin.label)
             {
                 fontSize = (int)(11 * GuiDisplaySize.Offset),
                 fontStyle = FontStyle.Bold,
@@ -656,21 +712,21 @@
                 stretchWidth = true
             };
 
-            this.settingStyle = new GUIStyle(this.titleStyle)
+            settingStyle = new GUIStyle(titleStyle)
             {
                 alignment = TextAnchor.MiddleLeft,
                 stretchWidth = true,
                 stretchHeight = true
             };
 
-            this.settingAtmoStyle = new GUIStyle(this.titleStyle)
+            settingAtmoStyle = new GUIStyle(titleStyle)
             {
                 margin = new RectOffset(),
                 padding = new RectOffset(),
                 alignment = TextAnchor.UpperLeft
             };
 
-            this.bodiesButtonStyle = new GUIStyle(HighLogic.Skin.button)
+            bodiesButtonStyle = new GUIStyle(HighLogic.Skin.button)
             {
                 margin = new RectOffset(0, 0, 2, 0),
                 padding = new RectOffset(5, 5, 5, 5),
@@ -688,10 +744,10 @@
                 fixedHeight = 20.0f
             };
 
-            this.bodiesButtonActiveStyle = new GUIStyle(this.bodiesButtonStyle)
-            {
-                normal = this.bodiesButtonStyle.onNormal,
-                hover = this.bodiesButtonStyle.onHover
+            bodiesButtonActiveStyle = new GUIStyle(bodiesButtonStyle)
+            {
+                normal = bodiesButtonStyle.onNormal,
+                hover = bodiesButtonStyle.onHover
             };
         }
 
@@ -702,15 +758,15 @@
         {
             try
             {
-                var handler = SettingHandler.Load("BuildAdvanced.xml");
-                handler.Get("visible", ref this.visible);
-                this.position.x = handler.Get("windowPositionX", this.position.x);
-                this.position.y = handler.Get("windowPositionY", this.position.y);
-                handler.Get("compactMode", ref this.compactMode);
-                handler.Get("compactCollapseRight", ref this.compactCollapseRight);
-                handler.Get("showAllStages", ref this.showAllStages);
-                handler.Get("showAtmosphericDetails", ref this.showAtmosphericDetails);
-                handler.Get("showSettings", ref this.showSettings);
+                SettingHandler handler = SettingHandler.Load("BuildAdvanced.xml");
+                handler.Get("visible", ref visible);
+                position.x = handler.Get("windowPositionX", position.x);
+                position.y = handler.Get("windowPositionY", position.y);
+                handler.Get("compactMode", ref compactMode);
+                handler.Get("compactCollapseRight", ref compactCollapseRight);
+                handler.Get("showAllStages", ref showAllStages);
+                handler.Get("showAtmosphericDetails", ref showAtmosphericDetails);
+                handler.Get("showSettings", ref showSettings);
                 CelestialBodies.SetSelectedBody(handler.Get("selectedBodyName", CelestialBodies.SelectedBody.Name));
             }
             catch (Exception ex)
@@ -721,8 +777,8 @@
 
         private void OnSizeChanged()
         {
-            this.InitialiseStyles();
-            this.hasChanged = true;
+            InitialiseStyles();
+            hasChanged = true;
         }
 
         /// <summary>
@@ -732,77 +788,79 @@
         {
             try
             {
+                compactModeRect = new Rect(position.width - 70.0f * GuiDisplaySize.Offset, 5.0f, 65.0f * GuiDisplaySize.Offset, 20.0f);
+
                 // Draw the compact mode toggle.
-                if (GUI.Toggle(new Rect(this.position.width - 70.0f * GuiDisplaySize.Offset, 5.0f, 65.0f * GuiDisplaySize.Offset, 20.0f), this.compactMode, "COMPACT", this.buttonStyle) != this.compactMode)
-                {
-                    this.hasChanged = true;
-                    this.compactCheck = 2;
-                    this.compactRight = this.position.xMax;
-                    this.compactMode = !this.compactMode;
+                if (GUI.Toggle(compactModeRect, compactMode, "COMPACT", buttonStyle) != compactMode)
+                {
+                    hasChanged = true;
+                    compactCheck = 2;
+                    compactRight = position.xMax;
+                    compactMode = !compactMode;
                 }
 
                 // When not in compact mode draw the 'All Stages' and 'Atmospheric' toggles.
-                if (!this.compactMode)
-                {
-                    if (GUI.Toggle(new Rect(this.position.width - 143.0f * GuiDisplaySize.Offset, 5.0f, 70.0f * GuiDisplaySize.Offset, 20.0f), this.showSettings, "SETTINGS", this.buttonStyle) != this.showSettings)
+                if (!compactMode)
+                {
+                    if (GUI.Toggle(new Rect(position.width - 143.0f * GuiDisplaySize.Offset, 5.0f, 70.0f * GuiDisplaySize.Offset, 20.0f), showSettings, "SETTINGS", buttonStyle) != showSettings)
                     {
-                        this.hasChanged = true;
-                        this.showSettings = !this.showSettings;
+                        hasChanged = true;
+                        showSettings = !showSettings;
                     }
 
-                    if (GUI.Toggle(new Rect(this.position.width - 226.0f * GuiDisplaySize.Offset, 5.0f, 80.0f * GuiDisplaySize.Offset, 20.0f), this.showAllStages, "ALL STAGES", this.buttonStyle) != this.showAllStages)
+                    if (GUI.Toggle(new Rect(position.width - 226.0f * GuiDisplaySize.Offset, 5.0f, 80.0f * GuiDisplaySize.Offset, 20.0f), showAllStages, "ALL STAGES", buttonStyle) != showAllStages)
                     {
-                        this.hasChanged = true;
-                        this.showAllStages = !this.showAllStages;
+                        hasChanged = true;
+                        showAllStages = !showAllStages;
                     }
 
-                    if (GUI.Toggle(new Rect(this.position.width - 324.0f * GuiDisplaySize.Offset, 5.0f, 95.0f * GuiDisplaySize.Offset, 20.0f), this.showAtmosphericDetails, "ATMOSPHERIC", this.buttonStyle) != this.showAtmosphericDetails)
+                    if (GUI.Toggle(new Rect(position.width - 324.0f * GuiDisplaySize.Offset, 5.0f, 95.0f * GuiDisplaySize.Offset, 20.0f), showAtmosphericDetails, "ATMOSPHERIC", buttonStyle) != showAtmosphericDetails)
                     {
-                        this.hasChanged = true;
-                        this.showAtmosphericDetails = !this.showAtmosphericDetails;
+                        hasChanged = true;
+                        showAtmosphericDetails = !showAtmosphericDetails;
                     }
 
-                    this.bodiesListPosition = new Rect(this.position.width - 452.0f * GuiDisplaySize.Offset, 5.0f, 125.0f * GuiDisplaySize.Offset, 20.0f);
-                    this.bodiesList.enabled = GUI.Toggle(this.bodiesListPosition, this.bodiesList.enabled, "BODY: " + CelestialBodies.SelectedBody.Name.ToUpper(), this.buttonStyle);
-                    this.bodiesList.SetPosition(this.bodiesListPosition.Translate(this.position));
+                    bodiesListPosition = new Rect(position.width - 452.0f * GuiDisplaySize.Offset, 5.0f, 125.0f * GuiDisplaySize.Offset, 20.0f);
+                    bodiesList.enabled = GUI.Toggle(bodiesListPosition, bodiesList.enabled, "BODY: " + CelestialBodies.SelectedBody.Name.ToUpper(), buttonStyle);
+                    bodiesList.SetPosition(bodiesListPosition.Translate(position));
                 }
 
                 // Draw the main informational display box.
-                if (!this.compactMode)
-                {
-                    GUILayout.BeginHorizontal(this.areaStyle);
-                    this.DrawStageNumbers();
-                    this.DrawPartCount();
-                    this.DrawCost();
-                    this.DrawMass();
-                    this.DrawIsp();
-                    this.DrawThrust();
-                    this.DrawTorque();
-                    this.DrawTwr();
-                    this.DrawDeltaV();
-                    this.DrawBurnTime();
+                if (!compactMode)
+                {
+                    GUILayout.BeginHorizontal(areaStyle);
+                    DrawStageNumbers();
+                    DrawPartCount();
+                    DrawCost();
+                    DrawMass();
+                    DrawIsp();
+                    DrawThrust();
+                    DrawTorque();
+                    DrawTwr();
+                    DrawDeltaV();
+                    DrawBurnTime();
                     GUILayout.EndHorizontal();
 
-                    if (this.showAtmosphericDetails)
+                    if (showAtmosphericDetails)
                     {
-                        GUILayout.BeginVertical(this.areaSettingStyle);
-                        this.DrawAtmosphericDetails();
+                        GUILayout.BeginVertical(areaSettingStyle);
+                        DrawAtmosphericDetails();
                         GUILayout.EndVertical();
                     }
 
-                    if (this.showSettings)
+                    if (showSettings)
                     {
-                        GUILayout.BeginVertical(this.areaSettingStyle);
-                        this.DrawSettings();
+                        GUILayout.BeginVertical(areaSettingStyle);
+                        DrawSettings();
                         GUILayout.EndVertical();
                     }
                 }
                 else // Draw only a few details when in compact mode.
                 {
-                    GUILayout.BeginHorizontal(this.areaStyle);
-                    this.DrawStageNumbers();
-                    this.DrawTwr();
-                    this.DrawDeltaV();
+                    GUILayout.BeginHorizontal(areaStyle);
+                    DrawStageNumbers();
+                    DrawTwr();
+                    DrawDeltaV();
                     GUILayout.EndHorizontal();
                 }
 
@@ -813,7 +871,6 @@
                 Logger.Exception(ex, "BuildAdvanced.Window()");
             }
         }
-
         #endregion
     }
 }

--- a/KerbalEngineer/Editor/BuildOverlayPartInfo.cs
+++ b/KerbalEngineer/Editor/BuildOverlayPartInfo.cs
@@ -17,27 +17,35 @@
 //     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 // 
 
-#region Using Directives
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-using KerbalEngineer.Extensions;
-using KerbalEngineer.Helpers;
-
-using UnityEngine;
-
-#endregion
-
 namespace KerbalEngineer.Editor
 {
+    using System;
+    using System.Collections.Generic;
+    using Extensions;
+    using Helpers;
+    using UnityEngine;
+
     public class BuildOverlayPartInfo : MonoBehaviour
     {
-        #region Fields
-
         private static bool clickToOpen = true;
+        private static ModuleGenerator.GeneratorResource generatorResource;
+        private static ModuleAlternator moduleAlternator;
+        private static ModuleDataTransmitter moduleDataTransmitter;
+        private static ModuleDeployableSolarPanel moduleDeployableSolarPanel;
+        private static ModuleGenerator moduleGenerator;
+        private static ModuleGimbal moduleGimbal;
+        private static ModuleParachute moduleParachute;
+        private static ModuleRCS moduleRcs;
+        private static ModuleReactionWheel moduleReactionWheel;
+        private static ModuleResource moduleResource;
+        private static ModuleScienceExperiment moduleScienceExperiment;
         private static bool namesOnly;
+        private static Part part;
+        private static PartInfoItem partInfoItem;
+        private static PartResource partResource;
+        private static Propellant propellant;
+        private static PartExtensions.ProtoModuleDecoupler protoModuleDecoupler;
+        private static PartExtensions.ProtoModuleEngine protoModuleEngine;
         private static bool visible = true;
 
         private readonly List<PartInfoItem> infoItems = new List<PartInfoItem>();
@@ -47,44 +55,54 @@
         private bool showInfo;
         private bool skipFrame;
 
-        #endregion
-
-        #region Properties
-
         public static bool ClickToOpen
         {
-            get { return clickToOpen; }
-            set { clickToOpen = value; }
+            get
+            {
+                return clickToOpen;
+            }
+            set
+            {
+                clickToOpen = value;
+            }
         }
 
         public static bool Hidden { get; set; }
 
         public static bool NamesOnly
         {
-            get { return namesOnly; }
-            set { namesOnly = value; }
+            get
+            {
+                return namesOnly;
+            }
+            set
+            {
+                namesOnly = value;
+            }
         }
 
         public static bool Visible
         {
-            get { return visible; }
-            set { visible = value; }
-        }
-
-        #endregion
-
-        #region Methods: protected
+            get
+            {
+                return visible;
+            }
+            set
+            {
+                visible = value;
+            }
+        }
 
         protected void OnGUI()
         {
             try
             {
-                if (!Visible || Hidden || this.selectedPart == null)
+                if (!Visible || Hidden || selectedPart == null)
                 {
                     return;
                 }
 
-                this.position = GUILayout.Window(this.GetInstanceID(), this.position, this.Window, String.Empty, BuildOverlay.WindowStyle);
+                position = GUILayout.Window(GetInstanceID(), position, Window, String.Empty, BuildOverlay.WindowStyle);
             }
             catch (Exception ex)
 
@@ -102,62 +120,66 @@
                     return;
                 }
 
-                this.position.x = Mathf.Clamp(Input.mousePosition.x + 16.0f, 0.0f, Screen.width - this.position.width);
-                this.position.y = Mathf.Clamp(Screen.height - Input.mousePosition.y, 0.0f, Screen.height - this.position.height);
-                if (this.position.x < Input.mousePosition.x + 20.0f)
-                {
-                    this.position.y = Mathf.Clamp(this.position.y + 20.0f, 0.0f, Screen.height - this.position.height);
-                }
-                if (this.position.x < Input.mousePosition.x + 16.0f && this.position.y < Screen.height - Input.mousePosition.y)
-                {
-                    this.position.x = Input.mousePosition.x - 3 - this.position.width;
-                }
-
-                this.infoItems.Clear();
-                var part = EditorLogic.fetch.ship.parts.Find(p => p.stackIcon.highlightIcon) ?? EditorLogic.SelectedPart;
+                position.x = Mathf.Clamp(Input.mousePosition.x + 16.0f, 0.0f, Screen.width - position.width);
+                position.y = Mathf.Clamp(Screen.height - Input.mousePosition.y, 0.0f, Screen.height - position.height);
+                if (position.x < Input.mousePosition.x + 20.0f)
+                {
+                    position.y = Mathf.Clamp(position.y + 20.0f, 0.0f, Screen.height - position.height);
+                }
+                if (position.x < Input.mousePosition.x + 16.0f && position.y < Screen.height - Input.mousePosition.y)
+                {
+                    position.x = Input.mousePosition.x - 3 - position.width;
+                }
+
+                part = EditorLogic.fetch.ship.parts.Find(p => p.stackIcon.highlightIcon) ?? EditorLogic.SelectedPart;
                 if (part != null)
                 {
-                    if (!part.Equals(this.selectedPart))
-                    {
-                        this.selectedPart = part;
-                        this.ResetInfo();
-                    }
-                    if (NamesOnly || this.skipFrame)
-                    {
-                        this.skipFrame = false;
+                    if (!part.Equals(selectedPart))
+                    {
+                        selectedPart = part;
+                        ResetInfo();
+                    }
+                    if (NamesOnly || skipFrame)
+                    {
+                        skipFrame = false;
                         return;
                     }
 
-                    this.SetCostInfo();
-                    this.SetMassItems();
-                    this.SetResourceItems();
-                    this.SetEngineInfo();
-                    this.SetAlternatorInfo();
-                    this.SetGimbalInfo();
-                    this.SetRcsInfo();
-                    this.SetParachuteInfo();
-                    this.SetSasInfo();
-                    this.SetReactionWheelInfo();
-                    this.SetSolarPanelInfo();
-                    this.SetGeneratorInfo();
-                    this.SetDecouplerInfo();
-                    this.SetTransmitterInfo();
-                    this.SetScienceExperimentInfo();
-                    this.SetScienceContainerInfo();
-                    this.SetSingleActivationInfo();
-
-                    if (!this.showInfo && Input.GetMouseButtonDown(2))
-                    {
-                        this.showInfo = true;
-                    }
-                    else if (ClickToOpen && this.showInfo && Input.GetMouseButtonDown(2))
-                    {
-                        this.ResetInfo();
+                    if (!showInfo && Input.GetMouseButtonDown(2))
+                    {
+                        showInfo = true;
+                    }
+                    else if (ClickToOpen && showInfo && Input.GetMouseButtonDown(2))
+                    {
+                        ResetInfo();
+                    }
+
+                    if (showInfo)
+                    {
+                        PartInfoItem.Release(infoItems);
+                        infoItems.Clear();
+                        SetCostInfo();
+                        SetMassItems();
+                        SetResourceItems();
+                        SetEngineInfo();
+                        SetAlternatorInfo();
+                        SetGimbalInfo();
+                        SetRcsInfo();
+                        SetParachuteInfo();
+                        SetSasInfo();
+                        SetReactionWheelInfo();
+                        SetSolarPanelInfo();
+                        SetGeneratorInfo();
+                        SetDecouplerInfo();
+                        SetTransmitterInfo();
+                        SetScienceExperimentInfo();
+                        SetScienceContainerInfo();
+                        SetSingleActivationInfo();
                     }
                 }
                 else
                 {
-                    this.selectedPart = null;
+                    selectedPart = null;
                 }
             }
             catch (Exception ex)
@@ -166,277 +188,277 @@
             }
         }
 
-        #endregion
-
-        #region Methods: private
-
         private void ResetInfo()
         {
-            this.showInfo = !clickToOpen;
-            this.skipFrame = true;
-            this.position.width = namesOnly || clickToOpen ? 0.0f : 200.0f;
-            this.position.height = 0.0f;
+            showInfo = !clickToOpen;
+            skipFrame = true;
+            position.width = namesOnly || clickToOpen ? 0.0f : 200.0f;
+            position.height = 0.0f;
         }
 
         private void SetAlternatorInfo()
         {
-            if (!this.selectedPart.HasModule<ModuleAlternator>())
-            {
-                return;
-            }
-
-            var alternator = this.selectedPart.GetModule<ModuleAlternator>();
-            this.infoItems.Add(new PartInfoItem("Alternator"));
-            foreach (var resource in alternator.outputResources)
-            {
-                this.infoItems.Add(new PartInfoItem("\t" + resource.name, resource.rate.ToRate()));
+            moduleAlternator = selectedPart.GetModule<ModuleAlternator>();
+            if (moduleAlternator != null)
+            {
+                infoItems.Add(PartInfoItem.Create("Alternator"));
+                for (int i = 0; i < moduleAlternator.outputResources.Count; ++i)
+                {
+                    moduleResource = moduleAlternator.outputResources[i];
+                    infoItems.Add(PartInfoItem.Create("\t" + moduleResource.name, moduleResource.rate.ToRate()));
+                }
             }
         }
 
         private void SetCostInfo()
         {
-            this.infoItems.Add(new PartInfoItem("Cost", Units.ConcatF(this.selectedPart.GetCostDry(), this.selectedPart.GetCostWet())));
+            infoItems.Add(PartInfoItem.Create("Cost", Units.ConcatF(selectedPart.GetCostDry(), selectedPart.GetCostWet())));
         }
 
         private void SetDecouplerInfo()
         {
-            if (!this.selectedPart.IsDecoupler())
-            {
-                return;
-            }
-
-            var decoupler = this.selectedPart.GetProtoModuleDecoupler();
-            this.infoItems.Add(new PartInfoItem("Ejection Force", decoupler.EjectionForce.ToForce()));
-            if (decoupler.IsOmniDecoupler)
-            {
-                this.infoItems.Add(new PartInfoItem("Omni-directional"));
+            protoModuleDecoupler = selectedPart.GetProtoModuleDecoupler();
+            if (protoModuleDecoupler != null)
+            {
+                infoItems.Add(PartInfoItem.Create("Ejection Force", protoModuleDecoupler.EjectionForce.ToForce()));
+                if (protoModuleDecoupler.IsOmniDecoupler)
+                {
+                    infoItems.Add(PartInfoItem.Create("Omni-directional"));
+                }
             }
         }
 
         private void SetEngineInfo()
         {
-            if (!this.selectedPart.IsEngine())
-            {
-                return;
-            }
-
-            var engine = this.selectedPart.GetProtoModuleEngine();
-            this.infoItems.Add(new PartInfoItem("Thrust", Units.ToForce(engine.MinimumThrust, engine.MaximumThrust)));
-            this.infoItems.Add(new PartInfoItem("Isp", Units.ConcatF(engine.GetSpecificImpulse(1.0f), engine.GetSpecificImpulse(0.0f)) + "s"));
-            if (engine.Propellants.Count > 0)
-            {
-                this.infoItems.Add(new PartInfoItem("Propellants"));
-                var totalRatio = engine.Propellants.Sum(p => p.ratio);
-                foreach (var propellant in engine.Propellants)
-                {
-                    this.infoItems.Add(new PartInfoItem("\t" + propellant.name, (propellant.ratio / totalRatio).ToPercent()));
+            protoModuleEngine = selectedPart.GetProtoModuleEngine();
+            if (protoModuleEngine != null)
+            {
+                infoItems.Add(PartInfoItem.Create("Thrust", Units.ToForce(protoModuleEngine.MinimumThrust, protoModuleEngine.MaximumThrust)));
+                infoItems.Add(PartInfoItem.Create("Isp", Units.ConcatF(protoModuleEngine.GetSpecificImpulse(1.0f), protoModuleEngine.GetSpecificImpulse(0.0f)) + "s"));
+                if (protoModuleEngine.Propellants.Count > 0)
+                {
+                    infoItems.Add(PartInfoItem.Create("Propellants"));
+
+                    float totalRatio = 0.0f;
+                    for (int i = 0; i < protoModuleEngine.Propellants.Count; ++i)
+                    {
+                        totalRatio = totalRatio + protoModuleEngine.Propellants[i].ratio;
+                    }
+
+                    for (int i = 0; i < protoModuleEngine.Propellants.Count; ++i)
+                    {
+                        propellant = protoModuleEngine.Propellants[i];
+                        infoItems.Add(PartInfoItem.Create("\t" + propellant.name, (propellant.ratio / totalRatio).ToPercent()));
+                    }
                 }
             }
         }
 
         private void SetGeneratorInfo()
         {
-            if (!this.selectedPart.HasModule<ModuleGenerator>())
-            {
-                return;
-            }
-
-            var generator = this.selectedPart.GetModule<ModuleGenerator>();
-            if (generator.inputList.Count > 0)
-            {
-                this.infoItems.Add(new PartInfoItem("Generator Input"));
-                foreach (var resource in generator.inputList)
-                {
-                    this.infoItems.Add(new PartInfoItem("\t" + resource.name, resource.rate.ToRate()));
-                }
-            }
-            if (generator.outputList.Count > 0)
-            {
-                this.infoItems.Add(new PartInfoItem("Generator Output"));
-                foreach (var resource in generator.outputList)
-                {
-                    this.infoItems.Add(new PartInfoItem("\t" + resource.name, resource.rate.ToRate()));
-                }
-            }
-            if (generator.isAlwaysActive)
-            {
-                this.infoItems.Add(new PartInfoItem("Generator is Always Active"));
+            moduleGenerator = selectedPart.GetModule<ModuleGenerator>();
+            if (moduleGenerator != null)
+            {
+                if (moduleGenerator.inputList.Count > 0)
+                {
+                    infoItems.Add(PartInfoItem.Create("Generator Input"));
+                    for (int i = 0; i < moduleGenerator.inputList.Count; ++i)
+                    {
+                        generatorResource = moduleGenerator.inputList[i];
+                        infoItems.Add(PartInfoItem.Create("\t" + generatorResource.name, generatorResource.rate.ToRate()));
+                    }
+                }
+                if (moduleGenerator.outputList.Count > 0)
+                {
+                    infoItems.Add(PartInfoItem.Create("Generator Output"));
+                    for (int i = 0; i < moduleGenerator.outputList.Count; ++i)
+                    {
+                        generatorResource = moduleGenerator.outputList[i];
+                        infoItems.Add(PartInfoItem.Create("\t" + generatorResource.name, generatorResource.rate.ToRate()));
+                    }
+                }
+                if (moduleGenerator.isAlwaysActive)
+                {
+                    infoItems.Add(PartInfoItem.Create("Generator is Always Active"));
+                }
             }
         }
 
         private void SetGimbalInfo()
         {
-            if (!this.selectedPart.HasModule<ModuleGimbal>())
-            {
-                return;
-            }
-
-            var gimbal = this.selectedPart.GetModule<ModuleGimbal>();
-            this.infoItems.Add(new PartInfoItem("Thrust Vectoring", gimbal.gimbalRange.ToString("F2")));
+            moduleGimbal = selectedPart.GetModule<ModuleGimbal>();
+            if (moduleGimbal != null)
+            {
+                infoItems.Add(PartInfoItem.Create("Thrust Vectoring", moduleGimbal.gimbalRange.ToString("F2")));
+            }
         }
 
         private void SetMassItems()
         {
-            if (this.selectedPart.physicalSignificance == Part.PhysicalSignificance.FULL)
-            {
-                this.infoItems.Add(new PartInfoItem("Mass", Units.ToMass(this.selectedPart.GetDryMass(), this.selectedPart.GetWetMass())));
+            if (selectedPart.physicalSignificance == Part.PhysicalSignificance.FULL)
+            {
+                infoItems.Add(PartInfoItem.Create("Mass", Units.ToMass(selectedPart.GetDryMass(), selectedPart.GetWetMass())));
             }
         }
 
         private void SetParachuteInfo()
         {
-            if (!this.selectedPart.HasModule<ModuleParachute>())
-            {
-                return;
-            }
-
-            var parachute = this.selectedPart.GetModule<ModuleParachute>();
-            this.infoItems.Add(new PartInfoItem("Deployed Drag", Units.ConcatF(parachute.semiDeployedDrag, parachute.fullyDeployedDrag)));
-            this.infoItems.Add(new PartInfoItem("Deployment Altitude", parachute.deployAltitude.ToDistance()));
-            this.infoItems.Add(new PartInfoItem("Deployment Pressure", parachute.minAirPressureToOpen.ToString("F2")));
+            moduleParachute = selectedPart.GetModule<ModuleParachute>();
+            if (moduleParachute != null)
+            {
+                infoItems.Add(PartInfoItem.Create("Deployed Drag", Units.ConcatF(moduleParachute.semiDeployedDrag, moduleParachute.fullyDeployedDrag)));
+                infoItems.Add(PartInfoItem.Create("Deployment Altitude", moduleParachute.deployAltitude.ToDistance()));
+                infoItems.Add(PartInfoItem.Create("Deployment Pressure", moduleParachute.minAirPressureToOpen.ToString("F2")));
+            }
         }
 
         private void SetRcsInfo()
         {
-            if (!this.selectedPart.HasModule<ModuleRCS>())
-            {
-                return;
-            }
-
-            var rcs = this.selectedPart.GetModule<ModuleRCS>();
-            this.infoItems.Add(new PartInfoItem("Thruster Power", rcs.thrusterPower.ToForce()));
-            this.infoItems.Add(new PartInfoItem("Specific Impulse", Units.ConcatF(rcs.atmosphereCurve.Evaluate(1.0f), rcs.atmosphereCurve.Evaluate(0.0f)) + "s"));
+            moduleRcs = selectedPart.GetModule<ModuleRCS>();
+            if (moduleRcs != null)
+            {
+                infoItems.Add(PartInfoItem.Create("Thruster Power", moduleRcs.thrusterPower.ToForce()));
+                infoItems.Add(PartInfoItem.Create("Specific Impulse", Units.ConcatF(moduleRcs.atmosphereCurve.Evaluate(1.0f), moduleRcs.atmosphereCurve.Evaluate(0.0f)) + "s"));
+            }
         }
 
         private void SetReactionWheelInfo()
         {
-            if (!this.selectedPart.HasModule<ModuleReactionWheel>())
-            {
-                return;
-            }
-
-            var reactionWheel = this.selectedPart.GetModule<ModuleReactionWheel>();
-            this.infoItems.Add(new PartInfoItem("Reaction Wheel Torque"));
-            this.infoItems.Add(new PartInfoItem("\tPitch", reactionWheel.PitchTorque.ToTorque()));
-            this.infoItems.Add(new PartInfoItem("\tRoll", reactionWheel.RollTorque.ToTorque()));
-            this.infoItems.Add(new PartInfoItem("\tYaw", reactionWheel.YawTorque.ToTorque()));
-            foreach (var resource in reactionWheel.inputResources)
-            {
-                this.infoItems.Add(new PartInfoItem("\t" + resource.name, resource.rate.ToRate()));
+            moduleReactionWheel = selectedPart.GetModule<ModuleReactionWheel>();
+            if (moduleReactionWheel != null)
+            {
+                infoItems.Add(PartInfoItem.Create("Reaction Wheel Torque"));
+                infoItems.Add(PartInfoItem.Create("\tPitch", moduleReactionWheel.PitchTorque.ToTorque()));
+                infoItems.Add(PartInfoItem.Create("\tRoll", moduleReactionWheel.RollTorque.ToTorque()));
+                infoItems.Add(PartInfoItem.Create("\tYaw", moduleReactionWheel.YawTorque.ToTorque()));
+                for (int i = 0; i < moduleReactionWheel.inputResources.Count; ++i)
+                {
+                    moduleResource = moduleReactionWheel.inputResources[i];
+                    infoItems.Add(PartInfoItem.Create("\t" + moduleResource.name, moduleResource.rate.ToRate()));
+                }
             }
         }
 
         private void SetResourceItems()
         {
-            if (this.selectedPart.Resources.list.Any(r => !r.hideFlow))
-            {
-                this.infoItems.Add(new PartInfoItem("Resources"));
-                foreach (var resource in this.selectedPart.Resources.list.Where(r => !r.hideFlow))
-                {
-                    this.infoItems.Add(resource.GetDensity() > 0
-                        ? new PartInfoItem("\t" + resource.info.name, "(" + resource.GetMass().ToMass() + ") " + resource.amount.ToString("F1"))
-                        : new PartInfoItem("\t" + resource.info.name, resource.amount.ToString("F1")));
+            bool visibleResources = false;
+            for (int i = 0; i < selectedPart.Resources.list.Count; ++i)
+            {
+                if (selectedPart.Resources.list[i].hideFlow == false)
+                {
+                    visibleResources = true;
+                    break;
+                }
+            }
+            if (visibleResources)
+            {
+                infoItems.Add(PartInfoItem.Create("Resources"));
+                for (int i = 0; i < selectedPart.Resources.list.Count; ++i)
+                {
+                    partResource = selectedPart.Resources.list[i];
+
+                    if (partResource.hideFlow == false)
+                    {
+                        infoItems.Add(partResource.GetDensity() > 0
+                            ? PartInfoItem.Create("\t" + partResource.info.name, "(" + partResource.GetMass().ToMass() + ") " + partResource.amount.ToString("F1"))
+                            : PartInfoItem.Create("\t" + partResource.info.name, partResource.amount.ToString("F1")));
+                    }
                 }
             }
         }
 
         private void SetSasInfo()
         {
-            if (this.selectedPart.HasModule<ModuleSAS>())
-            {
-                this.infoItems.Add(new PartInfoItem("SAS Equiped"));
+            if (selectedPart.HasModule<ModuleSAS>())
+            {
+                infoItems.Add(PartInfoItem.Create("SAS Equiped"));
             }
         }
 
         private void SetScienceContainerInfo()
         {
-            if (this.selectedPart.HasModule<ModuleScienceContainer>())
-            {
-                this.infoItems.Add(new PartInfoItem("Science Container"));
+            if (selectedPart.HasModule<ModuleScienceContainer>())
+            {
+                infoItems.Add(PartInfoItem.Create("Science Container"));
             }
         }
 
         private void SetScienceExperimentInfo()
         {
-            if (!this.selectedPart.HasModule<ModuleScienceExperiment>())
-            {
-                return;
-            }
-
-            var experiment = this.selectedPart.GetModule<ModuleScienceExperiment>();
-            this.infoItems.Add(new PartInfoItem("Science Experiment", experiment.experimentActionName));
-            this.infoItems.Add(new PartInfoItem("\tTransmit Efficiency", experiment.xmitDataScalar.ToPercent()));
-            if (!experiment.rerunnable)
-            {
-                this.infoItems.Add(new PartInfoItem("\tSingle Usage"));
+            moduleScienceExperiment = selectedPart.GetModule<ModuleScienceExperiment>();
+            if (moduleScienceExperiment != null)
+            {
+                infoItems.Add(PartInfoItem.Create("Science Experiment", moduleScienceExperiment.experimentActionName));
+                infoItems.Add(PartInfoItem.Create("\tTransmit Efficiency", moduleScienceExperiment.xmitDataScalar.ToPercent()));
+                if (moduleScienceExperiment.rerunnable == false)
+                {
+                    infoItems.Add(PartInfoItem.Create("\tSingle Usage"));
+                }
             }
         }
 
         private void SetSingleActivationInfo()
         {
-            if (this.selectedPart.HasModule<ModuleAnimateGeneric>(m => m.isOneShot))
-            {
-                this.infoItems.Add(new PartInfoItem("Single Activation"));
+            if (selectedPart.HasModule<ModuleAnimateGeneric>(m => m.isOneShot))
+            {
+                infoItems.Add(PartInfoItem.Create("Single Activation"));
             }
         }
 
         private void SetSolarPanelInfo()
         {
-            if (!this.selectedPart.HasModule<ModuleDeployableSolarPanel>())
-            {
-                return;
-            }
-
-            var solarPanel = this.selectedPart.GetModule<ModuleDeployableSolarPanel>();
-            this.infoItems.Add(new PartInfoItem("Charge Rate", solarPanel.chargeRate.ToRate()));
-            if (solarPanel.isBreakable)
-            {
-                this.infoItems.Add(new PartInfoItem("Breakable"));
-            }
-            if (solarPanel.sunTracking)
-            {
-                this.infoItems.Add(new PartInfoItem("Sun Tracking"));
+            moduleDeployableSolarPanel = selectedPart.GetModule<ModuleDeployableSolarPanel>();
+            if (moduleDeployableSolarPanel != null)
+            {
+                infoItems.Add(PartInfoItem.Create("Charge Rate", moduleDeployableSolarPanel.chargeRate.ToRate()));
+                if (moduleDeployableSolarPanel.isBreakable)
+                {
+                    infoItems.Add(PartInfoItem.Create("Breakable"));
+                }
+                if (moduleDeployableSolarPanel.sunTracking)
+                {
+                    infoItems.Add(PartInfoItem.Create("Sun Tracking"));
+                }
             }
         }
 
         private void SetTransmitterInfo()
         {
-            if (!this.selectedPart.HasModule<ModuleDataTransmitter>())
-            {
-                return;
-            }
-
-            var transmitter = this.selectedPart.GetModule<ModuleDataTransmitter>();
-            this.infoItems.Add(new PartInfoItem("Packet Size", transmitter.packetSize.ToString("F2") + " Mits"));
-            this.infoItems.Add(new PartInfoItem("Bandwidth", (transmitter.packetInterval * transmitter.packetSize).ToString("F2") + "Mits/sec"));
-            this.infoItems.Add(new PartInfoItem(transmitter.requiredResource, transmitter.packetResourceCost.ToString("F2") + "/Packet"));
+            moduleDataTransmitter = selectedPart.GetModule<ModuleDataTransmitter>();
+            if (moduleDataTransmitter != null)
+            {
+                infoItems.Add(PartInfoItem.Create("Packet Size", moduleDataTransmitter.packetSize.ToString("F2") + " Mits"));
+                infoItems.Add(PartInfoItem.Create("Bandwidth", (moduleDataTransmitter.packetInterval * moduleDataTransmitter.packetSize).ToString("F2") + "Mits/sec"));
+                infoItems.Add(PartInfoItem.Create(moduleDataTransmitter.requiredResource, moduleDataTransmitter.packetResourceCost.ToString("F2") + "/Packet"));
+            }
         }
 
         private void Window(int windowId)
         {
             try
             {
-                GUILayout.Label(this.selectedPart.partInfo.title, BuildOverlay.TitleStyle);
-                if (this.showInfo)
-                {
-                    foreach (var item in this.infoItems)
-                    {
+                GUILayout.Label(selectedPart.partInfo.title, BuildOverlay.TitleStyle);
+                if (showInfo)
+                {
+                    for (int i = 0; i < infoItems.Count; ++i)
+                    {
+                        partInfoItem = infoItems[i];
                         GUILayout.Space(2.0f);
                         GUILayout.BeginHorizontal();
-                        if (item.Value != null)
+                        if (partInfoItem.Value != null)
                         {
-                            GUILayout.Label(item.Name + ":", BuildOverlay.NameStyle);
+                            GUILayout.Label(partInfoItem.Name + ":", BuildOverlay.NameStyle);
                             GUILayout.Space(25.0f);
-                            GUILayout.Label(item.Value, BuildOverlay.ValueStyle);
+                            GUILayout.Label(partInfoItem.Value, BuildOverlay.ValueStyle);
                         }
                         else
                         {
-                            GUILayout.Label(item.Name, BuildOverlay.NameStyle);
+                            GUILayout.Label(partInfoItem.Name, BuildOverlay.NameStyle);
                         }
                         GUILayout.EndHorizontal();
                     }
                 }
-                else if (this.infoItems.Count > 0)
+                else if (clickToOpen && namesOnly == false)
                 {
                     GUILayout.Space(2.0f);
                     GUILayout.Label("Click middle mouse to show more info...", BuildOverlay.NameStyle);
@@ -447,7 +469,5 @@
                 Logger.Exception(ex);
             }
         }
-
-        #endregion
     }
 }

--- a/KerbalEngineer/Editor/BuildOverlayResources.cs
+++ b/KerbalEngineer/Editor/BuildOverlayResources.cs
@@ -19,22 +19,18 @@
 
 #region Using Directives
 
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-using KerbalEngineer.Extensions;
-
-using UnityEngine;
-
 #endregion
 
 namespace KerbalEngineer.Editor
 {
+    using System;
+    using System.Collections.Generic;
+    using Extensions;
+    using UnityEngine;
+
     public class BuildOverlayResources : MonoBehaviour
     {
         #region Fields
-
         private static bool visible = true;
 
         private readonly Dictionary<int, ResourceInfoItem> resources = new Dictionary<int, ResourceInfoItem>();
@@ -45,40 +41,48 @@
         private Rect tabPosition;
         private Vector2 tabSize;
         private Rect windowPosition = new Rect(0.0f, 0.0f, BuildOverlay.MinimumWidth, 0.0f);
-
         #endregion
 
         #region Properties
-
         public static bool Visible
         {
-            get { return visible; }
-            set { visible = value; }
+            get
+            {
+                return visible;
+            }
+            set
+            {
+                visible = value;
+            }
         }
 
         public bool Open
         {
-            get { return this.open; }
-            set { this.open = value; }
-        }
-
+            get
+            {
+                return open;
+            }
+            set
+            {
+                open = value;
+            }
+        }
         #endregion
 
         #region Methods: protected
-
         protected void OnGUI()
         {
             try
             {
-                if (!Visible || this.resources.Count == 0 || EditorLogic.fetch.editorScreen != EditorScreen.Parts)
+                if (!Visible || resources.Count == 0 || EditorLogic.fetch.editorScreen != EditorScreen.Parts)
                 {
                     return;
                 }
 
-                this.open = GUI.Toggle(this.tabPosition, this.open, this.tabContent, BuildOverlay.TabStyle);
-                if (this.openPercent > 0.0)
-                {
-                    this.windowPosition = GUILayout.Window(this.GetInstanceID(), this.windowPosition, this.Window, String.Empty, BuildOverlay.WindowStyle);
+                open = GUI.Toggle(tabPosition, open, tabContent, BuildOverlay.TabStyle);
+                if (openPercent > 0.0)
+                {
+                    windowPosition = GUILayout.Window(GetInstanceID(), windowPosition, Window, String.Empty, BuildOverlay.WindowStyle);
                 }
             }
             catch (Exception ex)
@@ -91,8 +95,8 @@
         {
             try
             {
-                this.tabContent = new GUIContent("RESOURCES");
-                this.tabSize = BuildOverlay.TabStyle.CalcSize(this.tabContent);
+                tabContent = new GUIContent("RESOURCES");
+                tabSize = BuildOverlay.TabStyle.CalcSize(tabContent);
             }
             catch (Exception ex)
             {
@@ -109,66 +113,74 @@
                     return;
                 }
 
-                this.SetResources();
-                this.SetSlidePosition();
-            }
-            catch (Exception ex)
-            {
-                Logger.Exception(ex);
-            }
-        }
-
+                SetResources();
+                SetSlidePosition();
+            }
+            catch (Exception ex)
+            {
+                Logger.Exception(ex);
+            }
+        }
         #endregion
 
         #region Methods: private
+        private static Part part;
+        private static PartResource partResource;
 
         private void SetResources()
         {
-            var previousCount = this.resources.Count;
-            this.resources.Clear();
-            foreach (var resource in EditorLogic.fetch.ship.parts.SelectMany(p => p.Resources.list).Where(r => r.amount > 0.0))
-            {
-                if (this.resources.ContainsKey(resource.info.id))
-                {
-                    this.resources[resource.info.id].Amount += resource.amount;
-                }
-                else
-                {
-                    this.resources.Add(resource.info.id, new ResourceInfoItem(resource));
-                }
-            }
-
-            if (this.resources.Count < previousCount)
-            {
-                this.windowPosition.height = 0;
+            int previousCount = resources.Count;
+            resources.Clear();
+
+            for (int i = 0; i < EditorLogic.fetch.ship.parts.Count; ++i)
+            {
+                part = EditorLogic.fetch.ship.parts[i];
+                for (int j = 0; j < part.Resources.list.Count; ++j)
+                {
+                    partResource = part.Resources.list[j];
+
+                    if (resources.ContainsKey(partResource.info.id))
+                    {
+                        resources[partResource.info.id].Amount += partResource.amount;
+                    }
+                    else
+                    {
+                        resources.Add(partResource.info.id, new ResourceInfoItem(partResource));
+                    }
+                }
+            }
+
+            if (resources.Count < previousCount)
+            {
+                windowPosition.height = 0;
             }
         }
 
         private void SetSlidePosition()
         {
-            if (this.open && this.openPercent < 1.0f)
-            {
-                this.openPercent = Mathf.Clamp(this.openPercent + Time.deltaTime * BuildOverlay.TabSpeed, 0.0f, 1.0f);
-            }
-            else if (!this.open && this.openPercent > 0.0f)
-            {
-                this.openPercent = Mathf.Clamp(this.openPercent - Time.deltaTime * BuildOverlay.TabSpeed, 0.0f, 1.0f);
-            }
-
-            this.windowPosition.x = BuildOverlay.BuildOverlayVessel.WindowPosition.xMax + 5.0f;
-            this.windowPosition.y = Mathf.Lerp(Screen.height, Screen.height - this.windowPosition.height, this.openPercent);
-            this.tabPosition.width = this.tabSize.x;
-            this.tabPosition.height = this.tabSize.y;
-            this.tabPosition.x = this.windowPosition.x;
-            this.tabPosition.y = this.windowPosition.y - this.tabPosition.height;
+            if (open && openPercent < 1.0f)
+            {
+                openPercent = Mathf.Clamp(openPercent + Time.deltaTime * BuildOverlay.TabSpeed, 0.0f, 1.0f);
+            }
+            else if (!open && openPercent > 0.0f)
+            {
+                openPercent = Mathf.Clamp(openPercent - Time.deltaTime * BuildOverlay.TabSpeed, 0.0f, 1.0f);
+            }
+
+            windowPosition.x = BuildOverlay.BuildOverlayVessel.WindowPosition.xMax + 5.0f;
+            windowPosition.y = Mathf.Lerp(Screen.height, Screen.height - windowPosition.height, openPercent);
+            tabPosition.width = tabSize.x;
+            tabPosition.height = tabSize.y;
+            tabPosition.x = windowPosition.x;
+            tabPosition.y = windowPosition.y - tabPosition.height;
         }
 
         private void Window(int windowId)
         {
             try
             {
-                var firstItem = true;
-                foreach (var resource in this.resources)
+                bool firstItem = true;
+                foreach (KeyValuePair<int, ResourceInfoItem> resource in resources)
                 {
                     if (!firstItem)
                     {
@@ -197,7 +209,6 @@
                 Logger.Exception(ex);
             }
         }
-
         #endregion
     }
 }

--- a/KerbalEngineer/Editor/BuildOverlayVessel.cs
+++ b/KerbalEngineer/Editor/BuildOverlayVessel.cs
@@ -18,13 +18,11 @@
 // 
 
 #region Using Directives
-
 #endregion
 
 namespace KerbalEngineer.Editor
 {
     #region Using Directives
-
     using System;
     using System.Collections.Generic;
     using Helpers;
@@ -36,13 +34,10 @@
     public class BuildOverlayVessel : MonoBehaviour
     {
         #region Constants
-
         private const float Width = 175.0f;
-
         #endregion
 
         #region Fields
-
         private static bool visible = true;
 
         private readonly List<PartInfoItem> infoItems = new List<PartInfoItem>();
@@ -54,44 +49,61 @@
         private Rect tabPosition;
         private Vector2 tabSize;
         private Rect windowPosition = new Rect(330.0f, 0.0f, Width, 0.0f);
-
         #endregion
 
         #region Properties
-
         public static bool Visible
         {
-            get { return visible; }
-            set { visible = value; }
+            get
+            {
+                return visible;
+            }
+            set
+            {
+                visible = value;
+            }
         }
 
         public bool Open
         {
-            get { return this.open; }
-            set { this.open = value; }
+            get
+            {
+                return open;
+            }
+            set
+            {
+                open = value;
+            }
         }
 
         public Rect WindowPosition
         {
-            get { return this.windowPosition; }
+            get
+            {
+                return windowPosition;
+            }
         }
 
         public float WindowX
         {
-            get { return this.windowPosition.x; }
-            set { this.windowPosition.x = value; }
-        }
-
+            get
+            {
+                return windowPosition.x;
+            }
+            set
+            {
+                windowPosition.x = value;
+            }
+        }
         #endregion
 
         #region Methods
-
         protected void Awake()
         {
             try
             {
-                SimManager.OnReady -= this.GetStageInfo;
-                SimManager.OnReady += this.GetStageInfo;
+                SimManager.OnReady -= GetStageInfo;
+                SimManager.OnReady += GetStageInfo;
             }
             catch (Exception ex)
             {
@@ -108,10 +120,10 @@
                     return;
                 }
 
-                this.open = GUI.Toggle(this.tabPosition, this.open, this.tabContent, BuildOverlay.TabStyle);
-                if (this.openPercent > 0.0)
-                {
-                    this.windowPosition = GUILayout.Window(this.GetInstanceID(), this.windowPosition, this.VesselWindow, String.Empty, BuildOverlay.WindowStyle);
+                open = GUI.Toggle(tabPosition, open, tabContent, BuildOverlay.TabStyle);
+                if (openPercent > 0.0)
+                {
+                    windowPosition = GUILayout.Window(GetInstanceID(), windowPosition, VesselWindow, String.Empty, BuildOverlay.WindowStyle);
                 }
             }
             catch (Exception ex)
@@ -124,8 +136,8 @@
         {
             try
             {
-                this.tabContent = new GUIContent("VESSEL");
-                this.tabSize = BuildOverlay.TabStyle.CalcSize(this.tabContent);
+                tabContent = new GUIContent("VESSEL");
+                tabSize = BuildOverlay.TabStyle.CalcSize(tabContent);
             }
             catch (Exception ex)
             {
@@ -142,12 +154,12 @@
                     return;
                 }
 
-                if (this.openPercent > 0.0)
-                {
-                    this.SetVesselInfo();
-                }
-
-                this.SetSlidePosition();
+                if (openPercent > 0.0)
+                {
+                    SetVesselInfo();
+                }
+
+                SetSlidePosition();
             }
             catch (Exception ex)
             {
@@ -157,29 +169,29 @@
 
         private void GetStageInfo()
         {
-            this.lastStage = SimManager.LastStage;
+            lastStage = SimManager.LastStage;
         }
 
         private void SetSlidePosition()
         {
-            if (this.open && this.openPercent < 1.0f)
-            {
-                this.openPercent = Mathf.Clamp(this.openPercent + Time.deltaTime * BuildOverlay.TabSpeed, 0.0f, 1.0f);
-            }
-            else if (!this.open && this.openPercent > 0.0f)
-            {
-                this.openPercent = Mathf.Clamp(this.openPercent - Time.deltaTime * BuildOverlay.TabSpeed, 0.0f, 1.0f);
-            }
-
-            this.windowPosition.y = Mathf.Lerp(Screen.height, Screen.height - this.windowPosition.height, this.openPercent);
-            if (this.windowPosition.width < Width)
-            {
-                this.windowPosition.width = Width;
-            }
-            this.tabPosition.width = this.tabSize.x;
-            this.tabPosition.height = this.tabSize.y;
-            this.tabPosition.x = this.windowPosition.x;
-            this.tabPosition.y = this.windowPosition.y - this.tabPosition.height;
+            if (open && openPercent < 1.0f)
+            {
+                openPercent = Mathf.Clamp(openPercent + Time.deltaTime * BuildOverlay.TabSpeed, 0.0f, 1.0f);
+            }
+            else if (!open && openPercent > 0.0f)
+            {
+                openPercent = Mathf.Clamp(openPercent - Time.deltaTime * BuildOverlay.TabSpeed, 0.0f, 1.0f);
+            }
+
+            windowPosition.y = Mathf.Lerp(Screen.height, Screen.height - windowPosition.height, openPercent);
+            if (windowPosition.width < Width)
+            {
+                windowPosition.width = Width;
+            }
+            tabPosition.width = tabSize.x;
+            tabPosition.height = tabSize.y;
+            tabPosition.x = windowPosition.x;
+            tabPosition.y = windowPosition.y - tabPosition.height;
         }
 
         private void SetVesselInfo()
@@ -198,13 +210,14 @@
             SimManager.RequestSimulation();
             SimManager.TryStartSimulation();
 
-            if (this.lastStage != null)
-            {
-                this.infoItems.Clear();
-                this.infoItems.Add(new PartInfoItem("Delta-V", this.lastStage.deltaV.ToString("N0") + " / " + this.lastStage.totalDeltaV.ToString("N0") + "m/s"));
-                this.infoItems.Add(new PartInfoItem("Mass", Units.ToMass(this.lastStage.mass, this.lastStage.totalMass)));
-                this.infoItems.Add(new PartInfoItem("TWR", this.lastStage.thrustToWeight.ToString("F2") + " (" + this.lastStage.maxThrustToWeight.ToString("F2") + ")"));
-                this.infoItems.Add(new PartInfoItem("Parts", this.lastStage.partCount + " / " + this.lastStage.totalPartCount));
+            if (lastStage != null)
+            {
+                PartInfoItem.Release(infoItems);
+                infoItems.Clear();
+                infoItems.Add(PartInfoItem.Create("Delta-V", lastStage.deltaV.ToString("N0") + " / " + lastStage.totalDeltaV.ToString("N0") + "m/s"));
+                infoItems.Add(PartInfoItem.Create("Mass", Units.ToMass(lastStage.mass, lastStage.totalMass)));
+                infoItems.Add(PartInfoItem.Create("TWR", lastStage.thrustToWeight.ToString("F2") + " (" + lastStage.maxThrustToWeight.ToString("F2") + ")"));
+                infoItems.Add(PartInfoItem.Create("Parts", lastStage.partCount + " / " + lastStage.totalPartCount));
             }
         }
 
@@ -212,8 +225,8 @@
         {
             try
             {
-                var firstItem = true;
-                foreach (var item in this.infoItems)
+                bool firstItem = true;
+                foreach (PartInfoItem item in infoItems)
                 {
                     if (!firstItem)
                     {
@@ -240,7 +253,6 @@
                 Logger.Exception(ex);
             }
         }
-
         #endregion
     }
 }

--- a/KerbalEngineer/Editor/PartInfoItem.cs
+++ b/KerbalEngineer/Editor/PartInfoItem.cs
@@ -19,29 +19,38 @@
 
 namespace KerbalEngineer.Editor
 {
-    public class PartInfoItem
+    using VesselSimulator;
+
+    public class PartInfoItem : Pool<PartInfoItem>
     {
-        #region Constructors
-
-        public PartInfoItem(string name)
-        {
-            this.Name = name;
-        }
-
-        public PartInfoItem(string name, string value)
-        {
-            this.Name = name;
-            this.Value = value;
-        }
-
-        #endregion
-
-        #region Properties
-
         public string Name { get; set; }
 
         public string Value { get; set; }
 
-        #endregion
+        public static PartInfoItem Create(string name)
+        {
+            return GetPoolObject().Initialise(name);
+        }
+
+        public static PartInfoItem Create(string name, string value)
+        {
+            return GetPoolObject().Initialise(name, value);
+        }
+
+        public PartInfoItem Initialise(string name)
+        {
+            Name = name;
+            Value = string.Empty;
+
+            return this;
+        }
+
+        public PartInfoItem Initialise(string name, string value)
+        {
+            Name = name;
+            Value = value;
+
+            return this;
+        }
     }
 }

--- a/KerbalEngineer/EngineerGlobals.cs
+++ b/KerbalEngineer/EngineerGlobals.cs
@@ -33,7 +33,7 @@
         /// <summary>
         ///     Current version of the Kerbal Engineer assembly.
         /// </summary>
-        public const string AssemblyVersion = "1.0.16.3";
+        public const string AssemblyVersion = "1.0.16.4";
 
         #endregion
 

--- a/KerbalEngineer/Extensions/PartExtensions.cs
+++ b/KerbalEngineer/Extensions/PartExtensions.cs
@@ -17,21 +17,17 @@
 //     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 // 
 
-#region Using Directives
-
-using System;
-using System.Collections.Generic;
-using System.Linq;
-
-#endregion
-
 namespace KerbalEngineer.Extensions
 {
+    using System;
+    using System.Collections.Generic;
     using CompoundParts;
 
     public static class PartExtensions
     {
-        #region Methods: public
+        private static Part cachePart;
+        private static PartModule cachePartModule;
+        private static PartResource cachePartResource;
 
         /// <summary>
         ///     Gets whether the part contains a specific resource.
@@ -46,7 +42,14 @@
         /// </summary>
         public static bool ContainsResources(this Part part)
         {
-            return part.Resources.list.Count(p => p.amount > 0d) > 0;
+            for (int i = 0; i < part.Resources.list.Count; ++i)
+            {
+                if (part.Resources.list[i].amount > 0.0)
+                {
+                    return true;
+                }
+            }
+            return false;
         }
 
         /// <summary>
@@ -54,13 +57,16 @@
         /// </summary>
         public static bool EngineHasFuel(this Part part)
         {
-            if (part.HasModule<ModuleEngines>())
-            {
-                return part.GetModuleEngines().getFlameoutState;
-            }
-            if (part.HasModule<MultiModeEngine>())
-            {
-                return part.GetModuleMultiModeEngine().getFlameoutState;
+            cachePartModule = GetModule<ModuleEngines>(part);
+            if (cachePartModule != null)
+            {
+                return (cachePartModule as ModuleEngines).getFlameoutState;
+            }
+
+            cachePartModule = GetModuleMultiModeEngine(part);
+            if (cachePartModule != null)
+            {
+                return (cachePartModule as ModuleEnginesFX).getFlameoutState;
             }
 
             return false;
@@ -103,20 +109,19 @@
         /// </summary>
         public static double GetMaxThrust(this Part part)
         {
-            if (part.HasModule<ModuleEngines>())
-            {
-                return part.GetModuleEngines().maxThrust;
-            }
-            if (part.HasModule<MultiModeEngine>())
-            {
-                return part.GetModuleMultiModeEngine().maxThrust;
-            }
-            if (part.HasModule<ModuleEnginesFX>())
-            {
-                return part.GetModuleEnginesFx().maxThrust;
-            }
-
-            return 0d;
+            cachePartModule = GetModule<ModuleEngines>(part);
+            if (cachePartModule != null)
+            {
+                return (cachePartModule as ModuleEngines).maxThrust;
+            }
+
+            cachePartModule = GetModuleMultiModeEngine(part) ?? GetModule<ModuleEnginesFX>(part);
+            if (cachePartModule != null)
+            {
+                return (cachePartModule as ModuleEnginesFX).maxThrust;
+            }
+
+            return 0.0;
         }
 
         /// <summary>
@@ -124,7 +129,16 @@
         /// </summary>
         public static T GetModule<T>(this Part part) where T : PartModule
         {
-            return part.Modules.OfType<T>().FirstOrDefault();
+            PartModule partModule;
+            for (int i = 0; i < part.Modules.Count; ++i)
+            {
+                partModule = part.Modules[i];
+                if (partModule is T)
+                {
+                    return partModule as T;
+                }
+            }
+            return null;
         }
 
         /// <summary>
@@ -132,7 +146,7 @@
         /// </summary>
         public static T GetModule<T>(this Part part, string className) where T : PartModule
         {
-            return (T)Convert.ChangeType(part.Modules[className], typeof(T));
+            return part.Modules[className] as T;
         }
 
         /// <summary>
@@ -140,7 +154,7 @@
         /// </summary>
         public static T GetModule<T>(this Part part, int classId) where T : PartModule
         {
-            return (T)Convert.ChangeType(part.Modules[classId], typeof(T));
+            return part.Modules[classId] as T;
         }
 
         /// <summary>
@@ -148,7 +162,7 @@
         /// </summary>
         public static ModuleAlternator GetModuleAlternator(this Part part)
         {
-            return part.GetModule<ModuleAlternator>();
+            return GetModule<ModuleAlternator>(part);
         }
 
         /// <summary>
@@ -156,7 +170,7 @@
         /// </summary>
         public static ModuleDeployableSolarPanel GetModuleDeployableSolarPanel(this Part part)
         {
-            return part.GetModule<ModuleDeployableSolarPanel>();
+            return GetModule<ModuleDeployableSolarPanel>(part);
         }
 
         /// <summary>
@@ -164,12 +178,12 @@
         /// </summary>
         public static ModuleEngines GetModuleEngines(this Part part)
         {
-            return part.GetModule<ModuleEngines>();
+            return GetModule<ModuleEngines>(part);
         }
 
         public static ModuleEnginesFX GetModuleEnginesFx(this Part part)
         {
-            return part.GetModule<ModuleEnginesFX>();
+            return GetModule<ModuleEnginesFX>(part);
         }
 
         /// <summary>
@@ -177,7 +191,7 @@
         /// </summary>
         public static ModuleGenerator GetModuleGenerator(this Part part)
         {
-            return part.GetModule<ModuleGenerator>();
+            return GetModule<ModuleGenerator>(part);
         }
 
         /// <summary>
@@ -185,7 +199,7 @@
         /// </summary>
         public static ModuleGimbal GetModuleGimbal(this Part part)
         {
-            return part.GetModule<ModuleGimbal>();
+            return GetModule<ModuleGimbal>(part);
         }
 
         /// <summary>
@@ -193,8 +207,17 @@
         /// </summary>
         public static ModuleEnginesFX GetModuleMultiModeEngine(this Part part)
         {
-            var mode = part.GetModule<MultiModeEngine>().mode;
-            return part.Modules.OfType<ModuleEnginesFX>().FirstOrDefault(engine => engine.engineID == mode);
+            ModuleEnginesFX moduleEngineFx;
+            string mode = GetModule<MultiModeEngine>(part).mode;
+            for (int i = 0; i < part.Modules.Count; ++i)
+            {
+                moduleEngineFx = part.Modules[i] as ModuleEnginesFX;
+                if (moduleEngineFx != null && moduleEngineFx.engineID == mode)
+                {
+                    return moduleEngineFx;
+                }
+            }
+            return null;
         }
 
         /// <summary>
@@ -202,12 +225,12 @@
         /// </summary>
         public static ModuleParachute GetModuleParachute(this Part part)
         {
-            return part.GetModule<ModuleParachute>();
+            return GetModule<ModuleParachute>(part);
         }
 
         public static ModuleRCS GetModuleRcs(this Part part)
         {
-            return part.GetModule<ModuleRCS>();
+            return GetModule<ModuleRCS>(part);
         }
 
         /// <summary>
@@ -215,19 +238,30 @@
         /// </summary>
         public static List<T> GetModules<T>(this Part part) where T : PartModule
         {
-            return part.Modules.OfType<T>().ToList();
+            List<T> list = new List<T>();
+            for (int i = 0; i < part.Modules.Count; ++i)
+            {
+                T module = part.Modules[i] as T;
+                if (module != null)
+                {
+                    list.Add(module);
+                }
+            }
+            return list;
         }
 
         public static ProtoModuleDecoupler GetProtoModuleDecoupler(this Part part)
         {
-            if (HasModule<ModuleDecouple>(part))
-            {
-                return new ProtoModuleDecoupler(GetModule<ModuleDecouple>(part));
-            }
-            if (HasModule<ModuleAnchoredDecoupler>(part))
-            {
-                return new ProtoModuleDecoupler(GetModule<ModuleAnchoredDecoupler>(part));
-            }
+            cachePartModule = GetModule<ModuleDecouple>(part);
+            if (cachePartModule == null)
+            {
+                cachePartModule = GetModule<ModuleAnchoredDecoupler>(part);
+            }
+            if (cachePartModule != null)
+            {
+                return new ProtoModuleDecoupler(cachePartModule);
+            }
+
             return null;
         }
 
@@ -236,18 +270,18 @@
         /// </summary>
         public static ProtoModuleEngine GetProtoModuleEngine(this Part part)
         {
-            if (HasModule<ModuleEngines>(part))
-            {
-                return new ProtoModuleEngine(GetModule<ModuleEngines>(part));
-            }
-            if (HasModule<MultiModeEngine>(part))
-            {
-                return new ProtoModuleEngine(GetModuleMultiModeEngine(part));
-            }
-            if (HasModule<ModuleEnginesFX>(part))
-            {
-                return new ProtoModuleEngine(GetModule<ModuleEnginesFX>(part));
-            }
+            cachePartModule = GetModule<ModuleEngines>(part);
+            if (cachePartModule != null)
+            {
+                return new ProtoModuleEngine(cachePartModule);
+            }
+
+            cachePartModule = GetModuleMultiModeEngine(part) ?? GetModule<ModuleEnginesFX>(part);
+            if (cachePartModule != null)
+            {
+                return new ProtoModuleEngine(cachePartModule);
+            }
+
             return null;
         }
 
@@ -256,7 +290,13 @@
         /// </summary>
         public static double GetResourceCost(this Part part)
         {
-            return part.Resources.list.Sum(r => r.amount * r.info.unitCost);
+            double cost = 0.0;
+            for (int i = 0; i < part.Resources.list.Count; ++i)
+            {
+                cachePartResource = part.Resources.list[i];
+                cost = cost + (cachePartResource.amount * cachePartResource.info.unitCost);
+            }
+            return cost;
         }
 
         /// <summary>
@@ -264,7 +304,13 @@
         /// </summary>
         public static double GetResourceCostInverted(this Part part)
         {
-            return part.Resources.list.Sum(r => (r.maxAmount - r.amount) * r.info.unitCost);
+            double cost = 0.0;
+            for (int i = 0; i < part.Resources.list.Count; ++i)
+            {
+                cachePartResource = part.Resources.list[i];
+                cost = cost + ((cachePartResource.maxAmount - cachePartResource.amount) * cachePartResource.info.unitCost);
+            }
+            return cost;
         }
 
         /// <summary>
@@ -272,7 +318,13 @@
         /// </summary>
         public static double GetResourceCostMax(this Part part)
         {
-            return part.Resources.list.Sum(r => r.maxAmount * r.info.unitCost);
+            double cost = 0.0;
+            for (int i = 0; i < part.Resources.list.Count; ++i)
+            {
+                cachePartResource = part.Resources.list[i];
+                cost = cost + (cachePartResource.maxAmount * cachePartResource.info.unitCost);
+            }
+            return cost;
         }
 
         /// <summary>
@@ -280,20 +332,19 @@
         /// </summary>
         public static double GetSpecificImpulse(this Part part, float atmosphere)
         {
-            if (part.HasModule<ModuleEngines>())
-            {
-                return part.GetModuleEngines().atmosphereCurve.Evaluate(atmosphere);
-            }
-            if (part.HasModule<MultiModeEngine>())
-            {
-                return part.GetModuleMultiModeEngine().atmosphereCurve.Evaluate(atmosphere);
-            }
-            if (part.HasModule<ModuleEnginesFX>())
-            {
-                return part.GetModuleEnginesFx().atmosphereCurve.Evaluate(atmosphere);
-            }
-
-            return 0d;
+            cachePartModule = GetModule<ModuleEngines>(part);
+            if (cachePartModule != null)
+            {
+                return (cachePartModule as ModuleEngines).atmosphereCurve.Evaluate(atmosphere);
+            }
+
+            cachePartModule = GetModuleMultiModeEngine(part) ?? GetModule<ModuleEnginesFX>(part);
+            if (cachePartModule != null)
+            {
+                return (cachePartModule as ModuleEnginesFX).atmosphereCurve.Evaluate(atmosphere);
+            }
+
+            return 0.0;
         }
 
         /// <summary>
@@ -309,7 +360,14 @@
         /// </summary>
         public static bool HasModule<T>(this Part part) where T : PartModule
         {
-            return part.Modules.OfType<T>().Any();
+            for (int i = 0; i < part.Modules.Count; ++i)
+            {
+                if (part.Modules[i] is T)
+                {
+                    return true;
+                }
+            }
+            return false;
         }
 
         /// <summary>
@@ -317,7 +375,15 @@
         /// </summary>
         public static bool HasModule<T>(this Part part, Func<T, bool> predicate) where T : PartModule
         {
-            return part.Modules.OfType<T>().Any(predicate);
+            for (int i = 0; i < part.Modules.Count; ++i)
+            {
+                cachePartModule = part.Modules[i] as T;
+                if (cachePartModule != null && predicate(cachePartModule as T))
+                {
+                    return true;
+                }
+            }
+            return false;
         }
 
         /// <summary>
@@ -341,7 +407,8 @@
         /// </summary>
         public static bool HasOneShotAnimation(this Part part)
         {
-            return part.HasModule<ModuleAnimateGeneric>() && part.GetModule<ModuleAnimateGeneric>().isOneShot;
+            cachePartModule = GetModule<ModuleAnimateGeneric>(part);
+            return cachePartModule != null && (cachePartModule as ModuleAnimateGeneric).isOneShot;
         }
 
         /// <summary>
@@ -349,7 +416,7 @@
         /// </summary>
         public static bool IsCommandModule(this Part part)
         {
-            return part.HasModule<ModuleCommand>();
+            return HasModule<ModuleCommand>(part);
         }
 
         /// <summary>
@@ -357,7 +424,7 @@
         /// </summary>
         public static bool IsDecoupledInStage(this Part part, int stage)
         {
-            if ((part.IsDecoupler() || part.IsLaunchClamp()) && part.inverseStage == stage)
+            if ((IsDecoupler(part) || IsLaunchClamp(part)) && part.inverseStage == stage)
             {
                 return true;
             }
@@ -365,7 +432,7 @@
             {
                 return false;
             }
-            return part.parent.IsDecoupledInStage(stage);
+            return IsDecoupledInStage(part.parent, stage);
         }
 
         /// <summary>
@@ -373,7 +440,7 @@
         /// </summary>
         public static bool IsDecoupler(this Part part)
         {
-            return part.HasModule<ModuleDecouple>() || part.HasModule<ModuleAnchoredDecoupler>();
+            return HasModule<ModuleDecouple>(part) || HasModule<ModuleAnchoredDecoupler>(part);
         }
 
         /// <summary>
@@ -381,7 +448,7 @@
         /// </summary>
         public static bool IsEngine(this Part part)
         {
-            return part.HasModule<ModuleEngines>() || part.HasModule<ModuleEnginesFX>();
+            return HasModule<ModuleEngines>(part) || HasModule<ModuleEnginesFX>(part);
         }
 
         /// <summary>
@@ -389,7 +456,7 @@
         /// </summary>
         public static bool IsFuelLine(this Part part)
         {
-            return (HasModule<CModuleFuelLine>(part));
+            return HasModule<CModuleFuelLine>(part);
         }
 
         /// <summary>
@@ -397,7 +464,7 @@
         /// </summary>
         public static bool IsGenerator(this Part part)
         {
-            return part.HasModule<ModuleGenerator>();
+            return HasModule<ModuleGenerator>(part);
         }
 
         /// <summary>
@@ -405,7 +472,7 @@
         /// </summary>
         public static bool IsLaunchClamp(this Part part)
         {
-            return part.HasModule<LaunchClamp>();
+            return HasModule<LaunchClamp>(part);
         }
 
         /// <summary>
@@ -413,7 +480,7 @@
         /// </summary>
         public static bool IsParachute(this Part part)
         {
-            return part.HasModule<ModuleParachute>();
+            return HasModule<ModuleParachute>(part);
         }
 
         /// <summary>
@@ -421,14 +488,15 @@
         /// </summary>
         public static bool IsPrimary(this Part part, List<Part> partsList, PartModule module)
         {
-            foreach (var vesselPart in partsList)
-            {
-                if (!vesselPart.HasModule(module.ClassID))
+            for (int i = 0; i < partsList.Count; ++i)
+            {
+                cachePart = partsList[i];
+
+                if (HasModule(cachePart, module.ClassID) == false)
                 {
                     continue;
                 }
-
-                if (vesselPart == part)
+                if (cachePart == part)
                 {
                     return true;
                 }
@@ -440,7 +508,7 @@
 
         public static bool IsRcsModule(this Part part)
         {
-            return part.HasModule<ModuleRCS>();
+            return HasModule<ModuleRCS>(part);
         }
 
         /// <summary>
@@ -448,7 +516,7 @@
         /// </summary>
         public static bool IsSepratron(this Part part)
         {
-            return (part.IsSolidRocket() && part.ActivatesEvenIfDisconnected && part.IsDecoupledInStage(part.inverseStage));
+            return IsSolidRocket(part) && part.ActivatesEvenIfDisconnected && IsDecoupledInStage(part, part.inverseStage);
         }
 
         /// <summary>
@@ -456,7 +524,7 @@
         /// </summary>
         public static bool IsSolarPanel(this Part part)
         {
-            return part.HasModule<ModuleDeployableSolarPanel>();
+            return HasModule<ModuleDeployableSolarPanel>(part);
         }
 
         /// <summary>
@@ -464,160 +532,106 @@
         /// </summary>
         public static bool IsSolidRocket(this Part part)
         {
-            return (part.HasModule<ModuleEngines>() && part.GetModuleEngines().throttleLocked) || (part.HasModule<ModuleEnginesFX>() && part.GetModuleEnginesFx().throttleLocked);
-        }
-
-        #endregion
-
-        #region Nested Type: ProtoModuleDecoupler
+            return (HasModule<ModuleEngines>(part) && GetModuleEngines(part).throttleLocked) || (HasModule<ModuleEnginesFX>(part) && GetModuleEnginesFx(part).throttleLocked);
+        }
 
         public class ProtoModuleDecoupler
         {
-            #region Fields
-
             private readonly PartModule module;
 
-            #endregion
-
-            #region Constructors
-
             public ProtoModuleDecoupler(PartModule module)
             {
                 this.module = module;
 
                 if (this.module is ModuleDecouple)
                 {
-                    this.SetModuleDecouple();
+                    SetModuleDecouple();
                 }
                 else if (this.module is ModuleAnchoredDecoupler)
                 {
-                    this.SetModuleAnchoredDecoupler();
-                }
-            }
-
-            #endregion
-
-            #region Properties
+                    SetModuleAnchoredDecoupler();
+                }
+            }
 
             public double EjectionForce { get; private set; }
             public bool IsOmniDecoupler { get; private set; }
 
-            #endregion
-
-            #region Methods: private
-
             private void SetModuleAnchoredDecoupler()
             {
-                var decoupler = this.module as ModuleAnchoredDecoupler;
+                ModuleAnchoredDecoupler decoupler = module as ModuleAnchoredDecoupler;
                 if (decoupler == null)
                 {
                     return;
                 }
 
-                this.EjectionForce = decoupler.ejectionForce;
+                EjectionForce = decoupler.ejectionForce;
             }
 
             private void SetModuleDecouple()
             {
-                var decoupler = this.module as ModuleDecouple;
+                ModuleDecouple decoupler = module as ModuleDecouple;
                 if (decoupler == null)
                 {
                     return;
                 }
 
-                this.EjectionForce = decoupler.ejectionForce;
-                this.IsOmniDecoupler = decoupler.isOmniDecoupler;
-            }
-
-            #endregion
-        }
-
-        #endregion
-
-        #region Nested Type: ProtoModuleEngine
+                EjectionForce = decoupler.ejectionForce;
+                IsOmniDecoupler = decoupler.isOmniDecoupler;
+            }
+        }
 
         public class ProtoModuleEngine
         {
-            #region Fields
-
             private readonly PartModule module;
 
-            #endregion
-
-            #region Constructors
-
             public ProtoModuleEngine(PartModule module)
             {
                 this.module = module;
 
                 if (module is ModuleEngines)
                 {
-                    this.SetModuleEngines();
-                }
-                else if (module is ModuleEnginesFX)
-                {
-                    this.SetModuleEnginesFx();
-                }
-            }
-
-            #endregion
-
-            #region Properties
+                    SetModuleEngines();
+                }
+            }
 
             public double MaximumThrust { get; private set; }
             public double MinimumThrust { get; private set; }
             public List<Propellant> Propellants { get; private set; }
 
-            #endregion
-
-            #region Methods: public
-
             public float GetSpecificImpulse(float atmosphere)
             {
-                if (this.module is ModuleEngines)
-                {
-                    return (this.module as ModuleEngines).atmosphereCurve.Evaluate(atmosphere);
-                }
-                if (this.module is ModuleEnginesFX)
-                {
-                    return (this.module as ModuleEnginesFX).atmosphereCurve.Evaluate(atmosphere);
+                if (module is ModuleEngines)
+                {
+                    return (module as ModuleEngines).atmosphereCurve.Evaluate(atmosphere);
                 }
                 return 0.0f;
             }
 
-            #endregion
-
-            #region Methods: private
-
             private void SetModuleEngines()
             {
-                var engine = this.module as ModuleEngines;
+                ModuleEngines engine = module as ModuleEngines;
                 if (engine == null)
                 {
                     return;
                 }
 
-                this.MaximumThrust = engine.maxThrust * (engine.thrustPercentage * 0.01);
-                this.MinimumThrust = engine.minThrust;
-                this.Propellants = engine.propellants;
+                MaximumThrust = engine.maxThrust * (engine.thrustPercentage * 0.01);
+                MinimumThrust = engine.minThrust;
+                Propellants = engine.propellants;
             }
 
             private void SetModuleEnginesFx()
             {
-                var engine = this.module as ModuleEnginesFX;
+                ModuleEnginesFX engine = module as ModuleEnginesFX;
                 if (engine == null)
                 {
                     return;
                 }
 
-                this.MaximumThrust = engine.maxThrust * (engine.thrustPercentage * 0.01);
-                this.MinimumThrust = engine.minThrust;
-                this.Propellants = engine.propellants;
-            }
-
-            #endregion
-        }
-
-        #endregion
+                MaximumThrust = engine.maxThrust * (engine.thrustPercentage * 0.01);
+                MinimumThrust = engine.minThrust;
+                Propellants = engine.propellants;
+            }
+        }
     }
 }

--- a/KerbalEngineer/Helpers/ForceAccumulator.cs
+++ b/KerbalEngineer/Helpers/ForceAccumulator.cs
@@ -99,5 +99,12 @@
         {
             return GetMinTorqueForceApplicationPoint(avgApplicationPoint.Get());
         }
+
+	    public void Reset()
+	    {
+	        totalForce = Vector3d.zero;
+	        totalZeroOriginTorque = Vector3d.zero;
+            avgApplicationPoint.Reset();
+	    }
 	}
 }

--- a/KerbalEngineer/Helpers/Pool.cs
+++ b/KerbalEngineer/Helpers/Pool.cs
@@ -41,6 +41,14 @@
             }
         }
 
+        public static void Release(List<T> objList)
+        {
+            for (int i = 0; i < objList.Count; ++i)
+            {
+                Release(objList[i]);
+            }
+        }
+
         public static void ReleaseAll()
         {
             for (int i = 0; i < inUse.Count; ++i)

--- a/KerbalEngineer/VesselSimulator/PartSim.cs
+++ b/KerbalEngineer/VesselSimulator/PartSim.cs
@@ -19,26 +19,22 @@
 
 #region Using Directives
 
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-using KerbalEngineer.Extensions;
-
-using UnityEngine;
-
 #endregion
 
 namespace KerbalEngineer.VesselSimulator
 {
+    using System;
+    using System.Collections.Generic;
+    using System.Linq;
+    using System.Text;
     using CompoundParts;
+    using Extensions;
+    using UnityEngine;
 
     public class PartSim : Pool<PartSim>
     {
-        private readonly List<AttachNodeSim> attachNodes = new List<AttachNodeSim>();
+        public double baseMass;
         public Vector3d centerOfMass;
-        public double baseMass;
         public double cost;
         public int decoupledInStage;
         public bool fuelCrossFeed;
@@ -70,6 +66,636 @@
         public double startMass = 0d;
         public String vesselName;
         public VesselType vesselType;
+        private readonly List<AttachNodeSim> attachNodes = new List<AttachNodeSim>();
+
+        public ResourceContainer ResourceDrains
+        {
+            get
+            {
+                return resourceDrains;
+            }
+        }
+
+        public ResourceContainer Resources
+        {
+            get
+            {
+                return resources;
+            }
+        }
+
+        public void CreateEngineSims(List<EngineSim> allEngines, double atmosphere, double mach, bool vectoredThrust, bool fullThrust, LogMsg log)
+        {
+            bool correctThrust = SimManager.DoesEngineUseCorrectedThrust(part);
+            if (log != null)
+            {
+                log.buf.AppendLine("CreateEngineSims for " + name);
+
+                foreach (PartModule partMod in part.Modules)
+                {
+                    log.buf.AppendLine("Module: " + partMod.moduleName);
+                }
+
+                log.buf.AppendLine("correctThrust = " + correctThrust);
+            }
+
+            if (hasMultiModeEngine)
+            {
+                // A multi-mode engine has multiple ModuleEnginesFX but only one is active at any point
+                // The mode of the engine is the engineID of the ModuleEnginesFX that is active
+                string mode = part.GetModule<MultiModeEngine>().mode;
+
+                List<ModuleEnginesFX> engines = part.GetModules<ModuleEnginesFX>();
+
+                for (int i = 0; i < engines.Count; ++i)
+                {
+                    ModuleEnginesFX engine = engines[i];
+
+                    if (engine.engineID == mode)
+                    {
+                        if (log != null)
+                        {
+                            log.buf.AppendLine("Module: " + engine.moduleName);
+                        }
+
+                        Vector3 thrustvec = CalculateThrustVector(vectoredThrust ? engine.thrustTransforms : null, log);
+
+                        EngineSim engineSim = EngineSim.GetPoolObject().Initialise(this,
+                            atmosphere,
+                            (float)mach,
+                            engine.maxFuelFlow,
+                            engine.minFuelFlow,
+                            engine.thrustPercentage,
+                            thrustvec,
+                            engine.atmosphereCurve,
+                            engine.atmChangeFlow,
+                            engine.useAtmCurve ? engine.atmCurve : null,
+                            engine.useVelCurve ? engine.velCurve : null,
+                            engine.currentThrottle,
+                            engine.throttleLocked || fullThrust,
+                            engine.propellants,
+                            engine.isOperational,
+                            engine.resultingThrust,
+                            engine.thrustTransforms);
+                        allEngines.Add(engineSim);
+                    }
+                }
+            }
+            else
+            {
+                if (hasModuleEngines)
+                {
+                    List<ModuleEngines> engines = part.GetModules<ModuleEngines>();
+                    for (int i = 0; i < engines.Count; ++i)
+                    {
+                        ModuleEngines engine = engines[i];
+                        if (log != null)
+                        {
+                            log.buf.AppendLine("Module: " + engine.moduleName);
+                        }
+
+                        Vector3 thrustvec = CalculateThrustVector(vectoredThrust ? engine.thrustTransforms : null, log);
+
+                        EngineSim engineSim = EngineSim.GetPoolObject().Initialise(this,
+                            atmosphere,
+                            (float)mach,
+                            engine.maxFuelFlow,
+                            engine.minFuelFlow,
+                            engine.thrustPercentage,
+                            thrustvec,
+                            engine.atmosphereCurve,
+                            engine.atmChangeFlow,
+                            engine.useAtmCurve ? engine.atmCurve : null,
+                            engine.useVelCurve ? engine.velCurve : null,
+                            engine.currentThrottle,
+                            engine.throttleLocked || fullThrust,
+                            engine.propellants,
+                            engine.isOperational,
+                            engine.resultingThrust,
+                            engine.thrustTransforms);
+                        allEngines.Add(engineSim);
+                    }
+                }
+            }
+
+            if (log != null)
+            {
+                log.Flush();
+            }
+        }
+
+        public int DecouplerCount()
+        {
+            int count = 0;
+            PartSim partSim = this;
+            while (partSim != null)
+            {
+                if (partSim.isDecoupler)
+                {
+                    count++;
+                }
+
+                partSim = partSim.parent;
+            }
+            return count;
+        }
+
+        public void DrainResources(double time)
+        {
+            //MonoBehaviour.print("DrainResources(" + name + ":" + partId + ", " + time + ")");
+            for (int i = 0; i < resourceDrains.Types.Count; ++i)
+            {
+                int type = resourceDrains.Types[i];
+
+                //MonoBehaviour.print("draining " + (time * resourceDrains[type]) + " " + ResourceContainer.GetResourceName(type));
+                resources.Add(type, -time * resourceDrains[type]);
+                //MonoBehaviour.print(ResourceContainer.GetResourceName(type) + " left = " + resources[type]);
+            }
+        }
+
+        public String DumpPartAndParentsToBuffer(StringBuilder buffer, String prefix)
+        {
+            if (parent != null)
+            {
+                prefix = parent.DumpPartAndParentsToBuffer(buffer, prefix) + " ";
+            }
+
+            DumpPartToBuffer(buffer, prefix);
+
+            return prefix;
+        }
+
+        public void DumpPartToBuffer(StringBuilder buffer, String prefix, List<PartSim> allParts = null)
+        {
+            buffer.Append(prefix);
+            buffer.Append(name);
+            buffer.AppendFormat(":[id = {0:d}, decouple = {1:d}, invstage = {2:d}", partId, decoupledInStage, inverseStage);
+
+            buffer.AppendFormat(", vesselName = '{0}'", vesselName);
+            buffer.AppendFormat(", vesselType = {0}", SimManager.GetVesselTypeString(vesselType));
+            buffer.AppendFormat(", initialVesselName = '{0}'", initialVesselName);
+
+            buffer.AppendFormat(", fuelCF = {0}", fuelCrossFeed);
+            buffer.AppendFormat(", noCFNKey = '{0}'", noCrossFeedNodeKey);
+
+            buffer.AppendFormat(", isSep = {0}", isSepratron);
+
+            foreach (int type in resources.Types)
+            {
+                buffer.AppendFormat(", {0} = {1:g6}", ResourceContainer.GetResourceName(type), resources[type]);
+            }
+
+            if (attachNodes.Count > 0)
+            {
+                buffer.Append(", attached = <");
+                attachNodes[0].DumpToBuffer(buffer);
+                for (int i = 1; i < attachNodes.Count; i++)
+                {
+                    buffer.Append(", ");
+                    attachNodes[i].DumpToBuffer(buffer);
+                }
+                buffer.Append(">");
+            }
+
+            // Add more info here
+
+            buffer.Append("]\n");
+
+            if (allParts != null)
+            {
+                String newPrefix = prefix + " ";
+                foreach (PartSim partSim in allParts)
+                {
+                    if (partSim.parent == this)
+                    {
+                        partSim.DumpPartToBuffer(buffer, newPrefix, allParts);
+                    }
+                }
+            }
+        }
+
+        public bool EmptyOf(HashSet<int> types)
+        {
+            foreach (int type in types)
+            {
+                if (resources.HasType(type) && resourceFlowStates[type] != 0 && resources[type] > SimManager.RESOURCE_MIN)
+                {
+                    return false;
+                }
+            }
+
+            return true;
+        }
+
+        public double GetMass()
+        {
+            double mass = baseMass;
+
+            for (int i = 0; i < resources.Types.Count; ++i)
+            {
+                mass += resources.GetResourceMass(resources.Types[i]);
+            }
+
+            return mass;
+        }
+
+        public HashSet<PartSim> GetSourceSet(int type, List<PartSim> allParts, HashSet<PartSim> visited, LogMsg log, String indent)
+        {
+            if (log != null)
+            {
+                log.buf.AppendLine(indent + "GetSourceSet(" + ResourceContainer.GetResourceName(type) + ") for " + name + ":" + partId);
+                indent += "  ";
+            }
+
+            HashSet<PartSim> allSources = new HashSet<PartSim>();
+            HashSet<PartSim> partSources = null;
+
+            // Rule 1: Each part can be only visited once, If it is visited for second time in particular search it returns empty list.
+            if (visited.Contains(this))
+            {
+                if (log != null)
+                {
+                    log.buf.AppendLine(indent + "Returning empty set, already visited (" + name + ":" + partId + ")");
+                }
+
+                return allSources;
+            }
+
+            //if (log != null)
+            //    log.buf.AppendLine(indent + "Adding this to visited");
+
+            visited.Add(this);
+
+            // Rule 2: Part performs scan on start of every fuel pipe ending in it. This scan is done in order in which pipes were installed.
+            // Then it makes an union of fuel tank sets each pipe scan returned. If the resulting list is not empty, it is returned as result.
+            //MonoBehaviour.print("foreach fuel line");
+            for (int i = 0; i < fuelTargets.Count; ++i)
+            {
+                PartSim partSim = fuelTargets[i];
+
+                if (visited.Contains(partSim))
+                {
+                    //if (log != null)
+                    //    log.buf.AppendLine(indent + "Fuel target already visited, skipping (" + partSim.name + ":" + partSim.partId + ")");
+                }
+                else
+                {
+                    //if (log != null)
+                    //    log.buf.AppendLine(indent + "Adding fuel target as source (" + partSim.name + ":" + partSim.partId + ")");
+
+                    partSources = partSim.GetSourceSet(type, allParts, visited, log, indent);
+                    if (partSources.Count > 0)
+                    {
+                        allSources.UnionWith(partSources);
+                        partSources.Clear();
+                    }
+                }
+            }
+
+            if (allSources.Count > 0)
+            {
+                if (log != null)
+                {
+                    log.buf.AppendLine(indent + "Returning " + allSources.Count + " fuel target sources (" + name + ":" + partId + ")");
+                }
+
+                return allSources;
+            }
+
+            // Rule 3: This rule has been removed and merged with rules 4 and 7 to fix issue with fuel tanks with disabled crossfeed
+
+            // Rule 4: Part performs scan on each of its axially mounted neighbors. 
+            //  Couplers (bicoupler, tricoupler, ...) are an exception, they only scan one attach point on the single attachment side,
+            //  skip the points on the side where multiple points are. [Experiment]
+            //  Again, the part creates union of scan lists from each of its neighbor and if it is not empty, returns this list. 
+            //  The order in which mount points of a part are scanned appears to be fixed and defined by the part specification file. [Experiment]
+            if (fuelCrossFeed)
+            {
+                //MonoBehaviour.print("foreach attach node");
+                for (int i = 0; i < attachNodes.Count; ++i)
+                {
+                    AttachNodeSim attachSim = attachNodes[i];
+
+                    if (attachSim.attachedPartSim != null)
+                    {
+                        if (attachSim.nodeType == AttachNode.NodeType.Stack)
+                        {
+                            if (!(noCrossFeedNodeKey != null && noCrossFeedNodeKey.Length > 0 && attachSim.id.Contains(noCrossFeedNodeKey)))
+                            {
+                                if (visited.Contains(attachSim.attachedPartSim))
+                                {
+                                    //if (log != null)
+                                    //    log.buf.AppendLine(indent + "Attached part already visited, skipping (" + attachSim.attachedPartSim.name + ":" + attachSim.attachedPartSim.partId + ")");
+                                }
+                                else
+                                {
+                                    //if (log != null)
+                                    //    log.buf.AppendLine(indent + "Adding attached part as source (" + attachSim.attachedPartSim.name + ":" + attachSim.attachedPartSim.partId + ")");
+
+                                    partSources = attachSim.attachedPartSim.GetSourceSet(type, allParts, visited, log, indent);
+                                    if (partSources.Count > 0)
+                                    {
+                                        allSources.UnionWith(partSources);
+                                        partSources.Clear();
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+
+                if (allSources.Count > 0)
+                {
+                    if (log != null)
+                    {
+                        log.buf.AppendLine(indent + "Returning " + allSources.Count + " attached sources (" + name + ":" + partId + ")");
+                    }
+
+                    return allSources;
+                }
+            }
+
+            // Rule 5: If the part is fuel container for searched type of fuel (i.e. it has capability to contain that type of fuel and the fuel 
+            // type was not disabled [Experiment]) and it contains fuel, it returns itself.
+            // Rule 6: If the part is fuel container for searched type of fuel (i.e. it has capability to contain that type of fuel and the fuel 
+            // type was not disabled) but it does not contain the requested fuel, it returns empty list. [Experiment]
+            if (resources.HasType(type) && resourceFlowStates[type] != 0)
+            {
+                if (resources[type] > SimManager.RESOURCE_MIN)
+                {
+                    allSources.Add(this);
+
+                    if (log != null)
+                    {
+                        log.buf.AppendLine(indent + "Returning enabled tank as only source (" + name + ":" + partId + ")");
+                    }
+                }
+
+                return allSources;
+            }
+
+            // Rule 7: If the part is radially attached to another part and it is child of that part in the ship's tree structure, it scans its 
+            // parent and returns whatever the parent scan returned. [Experiment] [Experiment]
+            if (parent != null && parentAttach == AttachModes.SRF_ATTACH)
+            {
+                if (fuelCrossFeed)
+                {
+                    if (visited.Contains(parent))
+                    {
+                        //if (log != null)
+                        //    log.buf.AppendLine(indent + "Parent part already visited, skipping (" + parent.name + ":" + parent.partId + ")");
+                    }
+                    else
+                    {
+                        allSources = parent.GetSourceSet(type, allParts, visited, log, indent);
+                        if (allSources.Count > 0)
+                        {
+                            if (log != null)
+                            {
+                                log.buf.AppendLine(indent + "Returning " + allSources.Count + " parent sources (" + name + ":" + partId + ")");
+                            }
+
+                            return allSources;
+                        }
+                    }
+                }
+            }
+
+            // Rule 8: If all preceding rules failed, part returns empty list.
+            //if (log != null)
+            //    log.buf.AppendLine(indent + "Returning empty set, no sources found (" + name + ":" + partId + ")");
+
+            return allSources;
+        }
+
+        public double GetStartMass()
+        {
+            return startMass;
+        }
+
+        public PartSim Initialise(Part thePart, int id, double atmosphere, LogMsg log)
+        {
+            Reset(this);
+
+            part = thePart;
+            centerOfMass = thePart.transform.TransformPoint(thePart.CoMOffset);
+            partId = id;
+            name = part.partInfo.name;
+
+            if (log != null)
+            {
+                log.buf.AppendLine("Create PartSim for " + name);
+            }
+
+            parent = null;
+            parentAttach = part.attachMode;
+            fuelCrossFeed = part.fuelCrossFeed;
+            noCrossFeedNodeKey = part.NoCrossFeedNodeKey;
+            decoupledInStage = DecoupledInStage(part);
+            isFuelLine = part.HasModule<CModuleFuelLine>();
+            isFuelTank = part is FuelTank;
+            isSepratron = IsSepratron();
+            inverseStage = part.inverseStage;
+            //MonoBehaviour.print("inverseStage = " + inverseStage);
+
+            cost = part.GetCostWet();
+
+            // Work out if the part should have no physical significance
+            isNoPhysics = part.HasModule<LaunchClamp>();
+
+            if (isNoPhysics == false)
+            {
+                if (part.vessel != null)
+                {
+                    baseMass = part.mass;
+                }
+                else
+                {
+                    baseMass = part.mass + part.GetModuleMass(part.mass);
+                }
+            }
+
+            if (SimManager.logOutput)
+            {
+                MonoBehaviour.print((isNoPhysics ? "Ignoring" : "Using") + " part.mass of " + part.mass);
+            }
+
+            for (int i = 0; i < part.Resources.Count; ++i)
+            {
+                PartResource resource = part.Resources[i];
+
+                // Make sure it isn't NaN as this messes up the part mass and hence most of the values
+                // This can happen if a resource capacity is 0 and tweakable
+                if (!Double.IsNaN(resource.amount))
+                {
+                    if (SimManager.logOutput)
+                    {
+                        MonoBehaviour.print(resource.resourceName + " = " + resource.amount);
+                    }
+
+                    resources.Add(resource.info.id, resource.amount);
+                    resourceFlowStates.Add(resource.info.id, resource.flowState ? 1 : 0);
+                }
+                else
+                {
+                    MonoBehaviour.print(resource.resourceName + " is NaN. Skipping.");
+                }
+            }
+
+            startMass = GetMass();
+
+            hasVessel = (part.vessel != null);
+            isLanded = hasVessel && part.vessel.Landed;
+            if (hasVessel)
+            {
+                vesselName = part.vessel.vesselName;
+                vesselType = part.vesselType;
+            }
+            initialVesselName = part.initialVesselName;
+
+            hasMultiModeEngine = part.HasModule<MultiModeEngine>();
+            hasModuleEnginesFX = part.HasModule<ModuleEnginesFX>();
+            hasModuleEngines = part.HasModule<ModuleEngines>();
+
+            isEngine = hasMultiModeEngine || hasModuleEnginesFX || hasModuleEngines;
+
+            if (SimManager.logOutput)
+            {
+                MonoBehaviour.print("Created " + name + ". Decoupled in stage " + decoupledInStage);
+            }
+
+            return this;
+        }
+
+        public void ReleasePart()
+        {
+            part = null;
+        }
+
+        public void RemoveAttachedParts(HashSet<PartSim> partSims)
+        {
+            // Loop through the attached parts
+            for (int i = 0; i < attachNodes.Count; ++i)
+            {
+                AttachNodeSim attachSim = attachNodes[i];
+
+                // If the part is in the set then "remove" it by clearing the PartSim reference
+                if (partSims.Contains(attachSim.attachedPartSim))
+                {
+                    attachSim.attachedPartSim = null;
+                }
+            }
+        }
+
+        public void SetupAttachNodes(Dictionary<Part, PartSim> partSimLookup, LogMsg log)
+        {
+            if (log != null)
+            {
+                log.buf.AppendLine("SetupAttachNodes for " + name + ":" + partId + "");
+            }
+
+            attachNodes.Clear();
+
+            for (int i = 0; i < part.attachNodes.Count; ++i)
+            {
+                AttachNode attachNode = part.attachNodes[i];
+
+                if (log != null)
+                {
+                    log.buf.AppendLine("AttachNode " + attachNode.id + " = " + (attachNode.attachedPart != null ? attachNode.attachedPart.partInfo.name : "null"));
+                }
+
+                if (attachNode.attachedPart != null && attachNode.id != "Strut")
+                {
+                    PartSim attachedSim;
+                    if (partSimLookup.TryGetValue(attachNode.attachedPart, out attachedSim))
+                    {
+                        if (log != null)
+                        {
+                            log.buf.AppendLine("Adding attached node " + attachedSim.name + ":" + attachedSim.partId + "");
+                        }
+
+                        attachNodes.Add(AttachNodeSim.GetPoolObject().Initialise(attachedSim, attachNode.id, attachNode.nodeType));
+                    }
+                    else
+                    {
+                        if (log != null)
+                        {
+                            log.buf.AppendLine("No PartSim for attached part (" + attachNode.attachedPart.partInfo.name + ")");
+                        }
+                    }
+                }
+            }
+
+            for (int i = 0; i < part.fuelLookupTargets.Count; ++i)
+            {
+                Part p = part.fuelLookupTargets[i];
+
+                if (p != null)
+                {
+                    PartSim targetSim;
+                    if (partSimLookup.TryGetValue(p, out targetSim))
+                    {
+                        if (log != null)
+                        {
+                            log.buf.AppendLine("Fuel target: " + targetSim.name + ":" + targetSim.partId);
+                        }
+
+                        fuelTargets.Add(targetSim);
+                    }
+                    else
+                    {
+                        if (log != null)
+                        {
+                            log.buf.AppendLine("No PartSim for fuel target (" + p.name + ")");
+                        }
+                    }
+                }
+            }
+        }
+
+        public void SetupParent(Dictionary<Part, PartSim> partSimLookup, LogMsg log)
+        {
+            if (part.parent != null)
+            {
+                parent = null;
+                if (partSimLookup.TryGetValue(part.parent, out parent))
+                {
+                    if (log != null)
+                    {
+                        log.buf.AppendLine("Parent part is " + parent.name + ":" + parent.partId);
+                    }
+                }
+                else
+                {
+                    if (log != null)
+                    {
+                        log.buf.AppendLine("No PartSim for parent part (" + part.parent.partInfo.name + ")");
+                    }
+                }
+            }
+        }
+
+        public double TimeToDrainResource()
+        {
+            //MonoBehaviour.print("TimeToDrainResource(" + name + ":" + partId + ")");
+            double time = double.MaxValue;
+
+            for (int i = 0; i < resourceDrains.Types.Count; ++i)
+            {
+                int type = resourceDrains.Types[i];
+
+                if (resourceDrains[type] > 0)
+                {
+                    time = Math.Min(time, resources[type] / resourceDrains[type]);
+                    //MonoBehaviour.print("type = " + ResourceContainer.GetResourceName(type) + "  amount = " + resources[type] + "  rate = " + resourceDrains[type] + "  time = " + time);
+                }
+            }
+
+            //if (time < double.MaxValue)
+            //    MonoBehaviour.print("TimeToDrainResource(" + name + ":" + partId + ") = " + time);
+            return time;
+        }
 
         private static void Reset(PartSim partSim)
         {
@@ -108,203 +734,6 @@
             partSim.vesselType = VesselType.Base;
         }
 
-        public PartSim Initialise(Part thePart, int id, double atmosphere, LogMsg log)
-        {
-            Reset(this);
-
-            this.part = thePart;
-            this.centerOfMass = thePart.transform.TransformPoint(thePart.CoMOffset);
-            this.partId = id;
-            this.name = this.part.partInfo.name;
-
-            if (log != null)
-            {
-                log.buf.AppendLine("Create PartSim for " + this.name);
-            }
-
-            this.parent = null;
-            this.parentAttach = part.attachMode;
-            this.fuelCrossFeed = this.part.fuelCrossFeed;
-            this.noCrossFeedNodeKey = this.part.NoCrossFeedNodeKey;
-            this.decoupledInStage = this.DecoupledInStage(this.part);
-            this.isFuelLine = this.part.HasModule<CModuleFuelLine>();
-            this.isFuelTank = this.part is FuelTank;
-            this.isSepratron = this.IsSepratron();
-            this.inverseStage = this.part.inverseStage;
-            //MonoBehaviour.print("inverseStage = " + inverseStage);
-
-            this.cost = this.part.GetCostWet();
-
-            // Work out if the part should have no physical significance
-            this.isNoPhysics = this.part.HasModule<LaunchClamp>();
-
-            if (isNoPhysics == false)
-            {
-                baseMass = part.mass;
-            }
-
-            if (SimManager.logOutput)
-            {
-                MonoBehaviour.print((this.isNoPhysics ? "Ignoring" : "Using") + " part.mass of " + this.part.mass);
-            }
-
-            for (int i = 0; i < part.Resources.Count; ++i)
-            {
-                PartResource resource = part.Resources[i];
-
-                // Make sure it isn't NaN as this messes up the part mass and hence most of the values
-                // This can happen if a resource capacity is 0 and tweakable
-                if (!Double.IsNaN(resource.amount))
-                {
-                    if (SimManager.logOutput)
-                    {
-                        MonoBehaviour.print(resource.resourceName + " = " + resource.amount);
-                    }
-
-                    this.resources.Add(resource.info.id, resource.amount);
-                    this.resourceFlowStates.Add(resource.info.id, resource.flowState ? 1 : 0);
-                }
-                else
-                {
-                    MonoBehaviour.print(resource.resourceName + " is NaN. Skipping.");
-                }
-            }
-
-            this.startMass = this.GetMass();
-
-            this.hasVessel = (this.part.vessel != null);
-            this.isLanded = this.hasVessel && this.part.vessel.Landed;
-            if (this.hasVessel)
-            {
-                this.vesselName = this.part.vessel.vesselName;
-                this.vesselType = this.part.vesselType;
-            }
-            this.initialVesselName = this.part.initialVesselName;
-
-            this.hasMultiModeEngine = this.part.HasModule<MultiModeEngine>();
-            this.hasModuleEnginesFX = this.part.HasModule<ModuleEnginesFX>();
-            this.hasModuleEngines = this.part.HasModule<ModuleEngines>();
-
-            this.isEngine = this.hasMultiModeEngine || this.hasModuleEnginesFX || this.hasModuleEngines;
-
-            if (SimManager.logOutput)
-            {
-                MonoBehaviour.print("Created " + this.name + ". Decoupled in stage " + this.decoupledInStage);
-            }
-
-            return this;
-        }
-
-        public ResourceContainer Resources
-        {
-            get { return this.resources; }
-        }
-
-        public ResourceContainer ResourceDrains
-        {
-            get { return this.resourceDrains; }
-        }
-
-        public void CreateEngineSims(List<EngineSim> allEngines, double atmosphere, double mach, bool vectoredThrust, bool fullThrust, LogMsg log)
-        {
-            bool correctThrust = SimManager.DoesEngineUseCorrectedThrust(this.part);
-            if (log != null)
-            {
-                log.buf.AppendLine("CreateEngineSims for " + this.name);
-
-                foreach (PartModule partMod in this.part.Modules)
-                {
-                    log.buf.AppendLine("Module: " + partMod.moduleName);
-                }
-
-                log.buf.AppendLine("correctThrust = " + correctThrust);
-            }
-
-            if (this.hasMultiModeEngine)
-            {
-                // A multi-mode engine has multiple ModuleEnginesFX but only one is active at any point
-                // The mode of the engine is the engineID of the ModuleEnginesFX that is active
-                string mode = this.part.GetModule<MultiModeEngine>().mode;
-
-                List<ModuleEnginesFX> engines = part.GetModules<ModuleEnginesFX>();
-
-                for (int i = 0; i < engines.Count; ++i)
-                {
-                    ModuleEnginesFX engine = engines[i];
-
-                    if (engine.engineID == mode)
-                    {
-                        if (log != null)
-                        {
-                            log.buf.AppendLine("Module: " + engine.moduleName);
-                        }
-
-                        Vector3 thrustvec = this.CalculateThrustVector(vectoredThrust ? engine.thrustTransforms : null, log);
-
-                        EngineSim engineSim = EngineSim.GetPoolObject().Initialise(this,
-                            atmosphere,
-                            (float)mach,
-                            engine.maxFuelFlow,
-                            engine.minFuelFlow,
-                            engine.thrustPercentage,
-                            thrustvec,
-                            engine.atmosphereCurve,
-                            engine.atmChangeFlow,
-                            engine.useAtmCurve ? engine.atmCurve : null,
-                            engine.useVelCurve ? engine.velCurve : null,
-                            engine.currentThrottle,
-                            engine.throttleLocked || fullThrust,
-                            engine.propellants,
-                            engine.isOperational,
-                            engine.resultingThrust,
-                            engine.thrustTransforms);
-                        allEngines.Add(engineSim);
-                    }
-                }
-            }
-            else
-            {
-                if (this.hasModuleEngines)
-                {
-                    List<ModuleEngines> engines = part.GetModules<ModuleEngines>();
-                    for (int i = 0; i < engines.Count; ++i)
-                    {
-                        ModuleEngines engine = engines[i];
-                        if (log != null)
-                        {
-                            log.buf.AppendLine("Module: " + engine.moduleName);
-                        }
-
-                        Vector3 thrustvec = this.CalculateThrustVector(vectoredThrust ? engine.thrustTransforms : null, log);
-
-                        EngineSim engineSim = EngineSim.GetPoolObject().Initialise(this,
-                            atmosphere,
-                            (float)mach,
-                            engine.maxFuelFlow,
-                            engine.minFuelFlow,
-                            engine.thrustPercentage,
-                            thrustvec,
-                            engine.atmosphereCurve,
-                            engine.atmChangeFlow,
-                            engine.useAtmCurve ? engine.atmCurve : null,
-                            engine.useVelCurve ? engine.velCurve : null,
-                            engine.currentThrottle,
-                            engine.throttleLocked || fullThrust,
-                            engine.propellants,
-                            engine.isOperational,
-                            engine.resultingThrust,
-                            engine.thrustTransforms);
-                        allEngines.Add(engineSim);
-                    }
-                }
-            }
-
-            if (log != null)
-            {
-                log.Flush();
-            }
-        }
-
         private Vector3 CalculateThrustVector(List<Transform> thrustTransforms, LogMsg log)
         {
             if (thrustTransforms == null)
@@ -340,98 +769,9 @@
             return thrustvec;
         }
 
-        public void SetupParent(Dictionary<Part, PartSim> partSimLookup, LogMsg log)
-        {
-            if (this.part.parent != null)
-            {
-                this.parent = null;
-                if (partSimLookup.TryGetValue(this.part.parent, out this.parent))
-                {
-                    if (log != null)
-                    {
-                        log.buf.AppendLine("Parent part is " + this.parent.name + ":" + this.parent.partId);
-                    }
-                }
-                else
-                {
-                    if (log != null)
-                    {
-                        log.buf.AppendLine("No PartSim for parent part (" + this.part.parent.partInfo.name + ")");
-                    }
-                }
-            }
-        }
-
-        public void SetupAttachNodes(Dictionary<Part, PartSim> partSimLookup, LogMsg log)
-        {
-            if (log != null)
-            {
-                log.buf.AppendLine("SetupAttachNodes for " + this.name + ":" + this.partId + "");
-            }
-
-            attachNodes.Clear();
-
-            for (int i = 0; i < part.attachNodes.Count; ++i)
-            {
-                AttachNode attachNode = part.attachNodes[i];
-
-                if (log != null)
-                {
-                    log.buf.AppendLine("AttachNode " + attachNode.id + " = " + (attachNode.attachedPart != null ? attachNode.attachedPart.partInfo.name : "null"));
-                }
-
-                if (attachNode.attachedPart != null && attachNode.id != "Strut")
-                {
-                    PartSim attachedSim;
-                    if (partSimLookup.TryGetValue(attachNode.attachedPart, out attachedSim))
-                    {
-                        if (log != null)
-                        {
-                            log.buf.AppendLine("Adding attached node " + attachedSim.name + ":" + attachedSim.partId + "");
-                        }
-
-                        attachNodes.Add(AttachNodeSim.GetPoolObject().Initialise(attachedSim, attachNode.id, attachNode.nodeType));
-                    }
-                    else
-                    {
-                        if (log != null)
-                        {
-                            log.buf.AppendLine("No PartSim for attached part (" + attachNode.attachedPart.partInfo.name + ")");
-                        }
-                    }
-                }
-            }
-
-            for (int i = 0; i < part.fuelLookupTargets.Count; ++i)
-            {
-                Part p = part.fuelLookupTargets[i];
-
-                if (p != null)
-                {
-                    PartSim targetSim;
-                    if (partSimLookup.TryGetValue(p, out targetSim))
-                    {
-                        if (log != null)
-                        {
-                            log.buf.AppendLine("Fuel target: " + targetSim.name + ":" + targetSim.partId);
-                        }
-
-                        this.fuelTargets.Add(targetSim);
-                    }
-                    else
-                    {
-                        if (log != null)
-                        {
-                            log.buf.AppendLine("No PartSim for fuel target (" + p.name + ")");
-                        }
-                    }
-                }
-            }
-        }
-
         private int DecoupledInStage(Part thePart, int stage = -1)
         {
-            if (this.IsDecoupler(thePart))
+            if (IsDecoupler(thePart))
             {
                 if (thePart.inverseStage > stage)
                 {
@@ -441,10 +781,16 @@
 
             if (thePart.parent != null)
             {
-                stage = this.DecoupledInStage(thePart.parent, stage);
+                stage = DecoupledInStage(thePart.parent, stage);
             }
 
             return stage;
+        }
+
+        private bool IsActiveDecoupler(Part thePart)
+        {
+            return thePart.FindModulesImplementing<ModuleDecouple>().Any(mod => !mod.isDecoupled) ||
+                   thePart.FindModulesImplementing<ModuleAnchoredDecoupler>().Any(mod => !mod.isDecoupled);
         }
 
         private bool IsDecoupler(Part thePart)
@@ -453,25 +799,19 @@
                    thePart.HasModule<ModuleAnchoredDecoupler>();
         }
 
-        private bool IsActiveDecoupler(Part thePart)
-        {
-            return thePart.FindModulesImplementing<ModuleDecouple>().Any(mod => !mod.isDecoupled) ||
-                   thePart.FindModulesImplementing<ModuleAnchoredDecoupler>().Any(mod => !mod.isDecoupled);
-        }
-
         private bool IsSepratron()
         {
-            if (!this.part.ActivatesEvenIfDisconnected)
+            if (!part.ActivatesEvenIfDisconnected)
             {
                 return false;
             }
 
-            if (this.part is SolidRocket)
+            if (part is SolidRocket)
             {
                 return true;
             }
 
-            var modList = this.part.Modules.OfType<ModuleEngines>();
+            IEnumerable<ModuleEngines> modList = part.Modules.OfType<ModuleEngines>();
             if (modList.Count() == 0)
             {
                 return false;
@@ -483,339 +823,6 @@
             }
 
             return false;
-        }
-
-        public void ReleasePart()
-        {
-            this.part = null;
-        }
-
-        // All functions below this point must not rely on the part member (it may be null)
-        //
-
-        public HashSet<PartSim> GetSourceSet(int type, List<PartSim> allParts, HashSet<PartSim> visited, LogMsg log, String indent)
-        {
-            if (log != null)
-            {
-                log.buf.AppendLine(indent + "GetSourceSet(" + ResourceContainer.GetResourceName(type) + ") for " + this.name + ":" + this.partId);
-                indent += "  ";
-            }
-
-            HashSet<PartSim> allSources = new HashSet<PartSim>();
-            HashSet<PartSim> partSources = null;
-
-            // Rule 1: Each part can be only visited once, If it is visited for second time in particular search it returns empty list.
-            if (visited.Contains(this))
-            {
-                if (log != null)
-                {
-                    log.buf.AppendLine(indent + "Returning empty set, already visited (" + this.name + ":" + this.partId + ")");
-                }
-
-                return allSources;
-            }
-
-            //if (log != null)
-            //    log.buf.AppendLine(indent + "Adding this to visited");
-
-            visited.Add(this);
-
-            // Rule 2: Part performs scan on start of every fuel pipe ending in it. This scan is done in order in which pipes were installed.
-            // Then it makes an union of fuel tank sets each pipe scan returned. If the resulting list is not empty, it is returned as result.
-            //MonoBehaviour.print("foreach fuel line");
-            for (int i = 0; i < fuelTargets.Count; ++i)
-            {
-                PartSim partSim = fuelTargets[i];
-
-                if (visited.Contains(partSim))
-                {
-                    //if (log != null)
-                    //    log.buf.AppendLine(indent + "Fuel target already visited, skipping (" + partSim.name + ":" + partSim.partId + ")");
-                }
-                else
-                {
-                    //if (log != null)
-                    //    log.buf.AppendLine(indent + "Adding fuel target as source (" + partSim.name + ":" + partSim.partId + ")");
-
-                    partSources = partSim.GetSourceSet(type, allParts, visited, log, indent);
-                    if (partSources.Count > 0)
-                    {
-                        allSources.UnionWith(partSources);
-                        partSources.Clear();
-                    }
-                }
-            }
-
-            if (allSources.Count > 0)
-            {
-                if (log != null)
-                {
-                    log.buf.AppendLine(indent + "Returning " + allSources.Count + " fuel target sources (" + this.name + ":" + this.partId + ")");
-                }
-
-                return allSources;
-            }
-
-            // Rule 3: This rule has been removed and merged with rules 4 and 7 to fix issue with fuel tanks with disabled crossfeed
-
-            // Rule 4: Part performs scan on each of its axially mounted neighbors. 
-            //  Couplers (bicoupler, tricoupler, ...) are an exception, they only scan one attach point on the single attachment side,
-            //  skip the points on the side where multiple points are. [Experiment]
-            //  Again, the part creates union of scan lists from each of its neighbor and if it is not empty, returns this list. 
-            //  The order in which mount points of a part are scanned appears to be fixed and defined by the part specification file. [Experiment]
-            if (this.fuelCrossFeed)
-            {
-                //MonoBehaviour.print("foreach attach node");
-                for (int i = 0; i < attachNodes.Count; ++i)
-                {
-                    AttachNodeSim attachSim = attachNodes[i];
-
-                    if (attachSim.attachedPartSim != null)
-                    {
-                        if (attachSim.nodeType == AttachNode.NodeType.Stack)
-                        {
-                            if (!(this.noCrossFeedNodeKey != null && this.noCrossFeedNodeKey.Length > 0 && attachSim.id.Contains(this.noCrossFeedNodeKey)))
-                            {
-                                if (visited.Contains(attachSim.attachedPartSim))
-                                {
-                                    //if (log != null)
-                                    //    log.buf.AppendLine(indent + "Attached part already visited, skipping (" + attachSim.attachedPartSim.name + ":" + attachSim.attachedPartSim.partId + ")");
-                                }
-                                else
-                                {
-                                    //if (log != null)
-                                    //    log.buf.AppendLine(indent + "Adding attached part as source (" + attachSim.attachedPartSim.name + ":" + attachSim.attachedPartSim.partId + ")");
-
-                                    partSources = attachSim.attachedPartSim.GetSourceSet(type, allParts, visited, log, indent);
-                                    if (partSources.Count > 0)
-                                    {
-                                        allSources.UnionWith(partSources);
-                                        partSources.Clear();
-                                    }
-                                }
-                            }
-                        }
-                    }
-                }
-
-                if (allSources.Count > 0)
-                {
-                    if (log != null)
-                    {
-                        log.buf.AppendLine(indent + "Returning " + allSources.Count + " attached sources (" + this.name + ":" + this.partId + ")");
-                    }
-
-                    return allSources;
-                }
-            }
-
-            // Rule 5: If the part is fuel container for searched type of fuel (i.e. it has capability to contain that type of fuel and the fuel 
-            // type was not disabled [Experiment]) and it contains fuel, it returns itself.
-            // Rule 6: If the part is fuel container for searched type of fuel (i.e. it has capability to contain that type of fuel and the fuel 
-            // type was not disabled) but it does not contain the requested fuel, it returns empty list. [Experiment]
-            if (this.resources.HasType(type) && this.resourceFlowStates[type] != 0)
-            {
-                if (this.resources[type] > SimManager.RESOURCE_MIN)
-                {
-                    allSources.Add(this);
-
-                    if (log != null)
-                    {
-                        log.buf.AppendLine(indent + "Returning enabled tank as only source (" + this.name + ":" + this.partId + ")");
-                    }
-                }
-
-                return allSources;
-            }
-
-            // Rule 7: If the part is radially attached to another part and it is child of that part in the ship's tree structure, it scans its 
-            // parent and returns whatever the parent scan returned. [Experiment] [Experiment]
-            if (this.parent != null && this.parentAttach == AttachModes.SRF_ATTACH)
-            {
-                if (this.fuelCrossFeed)
-                {
-                    if (visited.Contains(this.parent))
-                    {
-                        //if (log != null)
-                        //    log.buf.AppendLine(indent + "Parent part already visited, skipping (" + parent.name + ":" + parent.partId + ")");
-                    }
-                    else
-                    {
-                        allSources = this.parent.GetSourceSet(type, allParts, visited, log, indent);
-                        if (allSources.Count > 0)
-                        {
-                            if (log != null)
-                            {
-                                log.buf.AppendLine(indent + "Returning " + allSources.Count + " parent sources (" + this.name + ":" + this.partId + ")");
-                            }
-
-                            return allSources;
-                        }
-                    }
-                }
-            }
-
-            // Rule 8: If all preceding rules failed, part returns empty list.
-            //if (log != null)
-            //    log.buf.AppendLine(indent + "Returning empty set, no sources found (" + name + ":" + partId + ")");
-
-            return allSources;
-        }
-
-        public void RemoveAttachedParts(HashSet<PartSim> partSims)
-        {
-            // Loop through the attached parts
-            for (int i = 0; i < attachNodes.Count; ++i)
-            {
-                AttachNodeSim attachSim = attachNodes[i];
-
-                // If the part is in the set then "remove" it by clearing the PartSim reference
-                if (partSims.Contains(attachSim.attachedPartSim))
-                {
-                    attachSim.attachedPartSim = null;
-                }
-            }
-        }
-
-        public void DrainResources(double time)
-        {
-            //MonoBehaviour.print("DrainResources(" + name + ":" + partId + ", " + time + ")");
-            for (int i = 0; i < resourceDrains.Types.Count; ++i)
-            {
-                int type = resourceDrains.Types[i];
-
-                //MonoBehaviour.print("draining " + (time * resourceDrains[type]) + " " + ResourceContainer.GetResourceName(type));
-                this.resources.Add(type, -time * this.resourceDrains[type]);
-                //MonoBehaviour.print(ResourceContainer.GetResourceName(type) + " left = " + resources[type]);
-            }
-        }
-
-        public double TimeToDrainResource()
-        {
-            //MonoBehaviour.print("TimeToDrainResource(" + name + ":" + partId + ")");
-            double time = double.MaxValue;
-
-            for (int i = 0; i < resourceDrains.Types.Count; ++i)
-            {
-                int type = resourceDrains.Types[i];
-
-                if (this.resourceDrains[type] > 0)
-                {
-                    time = Math.Min(time, this.resources[type] / this.resourceDrains[type]);
-                    //MonoBehaviour.print("type = " + ResourceContainer.GetResourceName(type) + "  amount = " + resources[type] + "  rate = " + resourceDrains[type] + "  time = " + time);
-                }
-            }
-
-            //if (time < double.MaxValue)
-            //    MonoBehaviour.print("TimeToDrainResource(" + name + ":" + partId + ") = " + time);
-            return time;
-        }
-
-        public bool EmptyOf(HashSet<int> types)
-        {
-            foreach (int type in types)
-            {
-                if (this.resources.HasType(type) && this.resourceFlowStates[type] != 0 && (double)this.resources[type] > SimManager.RESOURCE_MIN)
-                {
-                    return false;
-                }
-            }
-
-            return true;
-        }
-
-        public int DecouplerCount()
-        {
-            int count = 0;
-            PartSim partSim = this;
-            while (partSim != null)
-            {
-                if (partSim.isDecoupler)
-                {
-                    count++;
-                }
-
-                partSim = partSim.parent;
-            }
-            return count;
-        }
-
-        public double GetStartMass()
-        {
-            return this.startMass;
-        }
-
-        public double GetMass()
-        {
-            double mass = this.baseMass;
-
-            for (int i = 0; i < resources.Types.Count; ++i)
-            {
-                mass += this.resources.GetResourceMass(resources.Types[i]);
-            }
-
-            return mass;
-        }
-
-        public String DumpPartAndParentsToBuffer(StringBuilder buffer, String prefix)
-        {
-            if (this.parent != null)
-            {
-                prefix = this.parent.DumpPartAndParentsToBuffer(buffer, prefix) + " ";
-            }
-
-            this.DumpPartToBuffer(buffer, prefix);
-
-            return prefix;
-        }
-
-        public void DumpPartToBuffer(StringBuilder buffer, String prefix, List<PartSim> allParts = null)
-        {
-            buffer.Append(prefix);
-            buffer.Append(this.name);
-            buffer.AppendFormat(":[id = {0:d}, decouple = {1:d}, invstage = {2:d}", this.partId, this.decoupledInStage, this.inverseStage);
-
-            buffer.AppendFormat(", vesselName = '{0}'", this.vesselName);
-            buffer.AppendFormat(", vesselType = {0}", SimManager.GetVesselTypeString(this.vesselType));
-            buffer.AppendFormat(", initialVesselName = '{0}'", this.initialVesselName);
-
-            buffer.AppendFormat(", fuelCF = {0}", this.fuelCrossFeed);
-            buffer.AppendFormat(", noCFNKey = '{0}'", this.noCrossFeedNodeKey);
-
-            buffer.AppendFormat(", isSep = {0}", this.isSepratron);
-
-            foreach (int type in this.resources.Types)
-            {
-                buffer.AppendFormat(", {0} = {1:g6}", ResourceContainer.GetResourceName(type), this.resources[type]);
-            }
-
-            if (this.attachNodes.Count > 0)
-            {
-                buffer.Append(", attached = <");
-                this.attachNodes[0].DumpToBuffer(buffer);
-                for (int i = 1; i < this.attachNodes.Count; i++)
-                {
-                    buffer.Append(", ");
-                    this.attachNodes[i].DumpToBuffer(buffer);
-                }
-                buffer.Append(">");
-            }
-
-            // Add more info here
-
-            buffer.Append("]\n");
-
-            if (allParts != null)
-            {
-                String newPrefix = prefix + " ";
-                foreach (PartSim partSim in allParts)
-                {
-                    if (partSim.parent == this)
-                    {
-                        partSim.DumpPartToBuffer(buffer, newPrefix, allParts);
-                    }
-                }
-            }
         }
     }
 }

--- a/KerbalEngineer/VesselSimulator/Simulation.cs
+++ b/KerbalEngineer/VesselSimulator/Simulation.cs
@@ -66,7 +66,7 @@
         private double totalStageFlowRate;
         private double totalStageIspFlowRate;
         private double totalStageThrust;
-        private ForceAccumulator totalStageThrustForce;
+        private ForceAccumulator totalStageThrustForce = new ForceAccumulator();
         private Vector3 vecActualThrust;
         private Vector3 vecStageDeltaV;
         private Vector3 vecThrust;
@@ -714,7 +714,7 @@
             this.totalStageActualThrust = 0d;
             this.totalStageFlowRate = 0d;
             this.totalStageIspFlowRate = 0d;
-            this.totalStageThrustForce = new ForceAccumulator();
+            this.totalStageThrustForce.Reset();
 
             // Loop through all the active engines totalling the thrust, actual thrust and mass flow rates
             // The thrust is totalled as vectors

 Binary files a/Output/KerbalEngineer/KerbalEngineer.dll and b/Output/KerbalEngineer/KerbalEngineer.dll differ
--- a/Output/KerbalEngineer/KerbalEngineer.version
+++ b/Output/KerbalEngineer/KerbalEngineer.version
@@ -6,12 +6,12 @@
 		"MAJOR":1,
 		"MINOR":0,
 		"PATCH":16,
-		"BUILD":3
+		"BUILD":4
 	},
 	"KSP_VERSION":
 	{
 		"MAJOR":1,
 		"MINOR":0,
-		"PATCH":0
+		"PATCH":1
 	}
 }