diff --git a/src/protocol/http/org/apache/jmeter/protocol/http/proxy/ProxyControl.java b/src/protocol/http/org/apache/jmeter/protocol/http/proxy/ProxyControl.java
index f0e8cb8..fc79fdc 100644
--- a/src/protocol/http/org/apache/jmeter/protocol/http/proxy/ProxyControl.java
+++ b/src/protocol/http/org/apache/jmeter/protocol/http/proxy/ProxyControl.java
@@ -222,6 +222,8 @@ public class ProxyControl extends GenericController {
     // If this is defined, it is assumed to be the alias of a user-supplied certificate; overrides dynamic mode
     static final String CERT_ALIAS = JMeterUtils.getProperty("proxy.cert.alias"); // $NON-NLS-1$
 
+    private static JMeterTreeModel treeModel = null;
+
     public enum KeystoreMode {
         USER_KEYSTORE,   // user-provided keystore
         JMETER_KEYSTORE, // keystore generated by JMeter; single entry
@@ -246,6 +248,10 @@ public class ProxyControl extends GenericController {
                 log.warn("HTTP(S) Test Script Recorder SSL Proxy will use keys that may not work for embedded resources in file " + CERT_PATH_ABS);
             }
         }
+
+        if (GuiPackage.getInstance() != null) {
+		treeModel = GuiPackage.getInstance().getTreeModel();
+        }
     }
 
     // Whether to use the redirect disabling feature (can be switched off if it does not work)
@@ -300,6 +306,14 @@ public class ProxyControl extends GenericController {
         setCaptureHttpHeaders(true); // maintain original behaviour
     }
 
+    /**
+     * When working without GUI required for operation
+     * @param treeModel JMeterTreeModel used for recording
+     */
+    public static void setGlobalTreeRoot(JMeterTreeModel treeModel) {
+	ProxyControl.treeModel = treeModel;
+    }
+
     public void setPort(int port) {
         this.setProperty(new IntegerProperty(PORT, port));
     }
@@ -485,6 +499,7 @@ public class ProxyControl extends GenericController {
         try {
             server = new Daemon(getPort(), this);
             server.start();
+            if (GuiPackage.getInstance() != null)
             GuiPackage.getInstance().register(server);
         } catch (IOException e) {
             log.error("Could not create Proxy daemon", e);
@@ -674,6 +689,7 @@ public class ProxyControl extends GenericController {
     public void stopProxy() {
         if (server != null) {
             server.stopServer();
+            if (GuiPackage.getInstance() != null)
             GuiPackage.getInstance().unregister(server);
             try {
                 server.join(1000); // wait for server to stop
@@ -972,7 +988,6 @@ public class ProxyControl extends GenericController {
      *         <code>null</code> if none was found.
      */
     private JMeterTreeNode findFirstNodeOfType(Class<?> type) {
-        JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
         List<JMeterTreeNode> nodes = treeModel.getNodesOfType(type);
         for (JMeterTreeNode node : nodes) {
             if (node.isEnabled()) {
@@ -1038,7 +1053,6 @@ public class ProxyControl extends GenericController {
      */
     // TODO - could be converted to generic class?
     private Collection<?> findApplicableElements(JMeterTreeNode myTarget, Class<? extends TestElement> myClass, boolean ascending) {
-        JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
         LinkedList<TestElement> elements = new LinkedList<>();
 
         // Look for elements directly within the HTTP proxy:
@@ -1096,8 +1110,6 @@ public class ProxyControl extends GenericController {
     private void placeSampler(final HTTPSamplerBase sampler, final TestElement[] subConfigs,
             JMeterTreeNode myTarget) {
         try {
-            final JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
-
             boolean firstInBatch = false;
             long now = System.currentTimeMillis();
             long deltaT = now - lastTime;
@@ -1288,7 +1300,6 @@ public class ProxyControl extends GenericController {
      *            sampling event to be delivered
      */
     private void notifySampleListeners(SampleEvent event) {
-        JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
         JMeterTreeNode myNode = treeModel.getNodeOf(this);
         Enumeration<JMeterTreeNode> kids = myNode.children();
         while (kids.hasMoreElements()) {
@@ -1307,7 +1318,6 @@ public class ProxyControl extends GenericController {
      * (here meaning the proxy recording) has started.
      */
     private void notifyTestListenersOfStart() {
-        JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
         JMeterTreeNode myNode = treeModel.getNodeOf(this);
         Enumeration<JMeterTreeNode> kids = myNode.children();
         while (kids.hasMoreElements()) {
@@ -1326,7 +1336,6 @@ public class ProxyControl extends GenericController {
      * (here meaning the proxy recording) has ended.
      */
     private void notifyTestListenersOfEnd() {
-        JMeterTreeModel treeModel = GuiPackage.getInstance().getTreeModel();
         JMeterTreeNode myNode = treeModel.getNodeOf(this);
         Enumeration<JMeterTreeNode> kids = myNode.children();
         while (kids.hasMoreElements()) {
