diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DoSetViewPort.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DoSetViewPort.java
index f61ea60f85913f553a4a03c668746d8849898c64..0d83e296f45cd6b36e78f72b4037a18dfdeed139 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DoSetViewPort.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/DoSetViewPort.java
@@ -74,6 +74,8 @@ final class DoSetViewPort extends RBaseNode {
         pushedVPData[ViewPort.PVP_CLIPRECT] = RDataFactory.createDoubleVector(new double[]{0, 0, 0, 0}, RDataFactory.COMPLETE_VECTOR);
         pushedVPData[ViewPort.PVP_DEVWIDTHCM] = scalar(Unit.inchesToCm(currentDevice.getWidth()));
         pushedVPData[ViewPort.PVP_DEVHEIGHTCM] = scalar(Unit.inchesToCm(currentDevice.getHeight()));
+
+        assert pushedViewPort.verify();
         return pushedViewPort;
     }
 
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridContext.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridContext.java
index 356fc3173b6ffea43e0c830bcc22d75ad33c71ef..4f14e7b14e02db035475251d1568b1de228056b8 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridContext.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridContext.java
@@ -82,7 +82,7 @@ public final class GridContext {
     public void openDefaultDevice() {
         String defaultDev = RGridGraphicsAdapter.getDefaultDevice();
         if (defaultDev.equals("awt") || defaultDev.startsWith("X11")) {
-            BufferedJFrameDevice result = new BufferedJFrameDevice(JFrameDevice.create());
+            BufferedJFrameDevice result = new BufferedJFrameDevice(JFrameDevice.create(GridDevice.DEFAULT_WIDTH, GridDevice.DEFAULT_HEIGHT));
             setCurrentDevice(defaultDev, result);
         } else {
             throw RError.error(RError.NO_CALLER, Message.GENERIC, "FastR does not support device '" + defaultDev + "'.");
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridLinesNode.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridLinesNode.java
index 8db8ff46c3412d83f496c751a747fc24888e9b62..32c5d9c52b349c34a6c394d6af0543521dd5191d 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridLinesNode.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridLinesNode.java
@@ -90,15 +90,17 @@ public abstract class GridLinesNode extends Node {
                     // (1) current is invalid point. Note: in (one of) the next iteration(s), the
                     // oldIsFinite will be false and we will update the start and start a new series
                     // (2) we are in the last iteration
-                    if (lastIter || i - start > 1) {
-                        // we draw only if the previous series of points was at least of length 3 or
-                        // it's last iteration. This seems slightly weird, but that's how GnuR seems
-                        // to work
-                        drawPolylines(dev, drawingCtx, yy, xx, start, (i - start) + 1);
+                    int length = i - start;
+                    if (currIsFinite) {
+                        // the length includes the last point only if the point is finite
+                        length++;
+                    }
+                    if (length > 1) {
+                        drawPolylines(dev, drawingCtx, yy, xx, start, length);
                         if (arrow != null) {
                             // Can draw an arrow at the start if the points include the first point.
                             // Draw an arrow at the end only if this is the last series
-                            drawArrowsNode.drawArrows(xx, yy, start, (i - start) + 1, unitIndex, arrow, start == 0, lastIter, conversionCtx);
+                            drawArrowsNode.drawArrows(xx, yy, start, length, unitIndex, arrow, start == 0, lastIter, conversionCtx);
                         }
                     }
                 }
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridState.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridState.java
index 321e0a022bae4fcc9d5ee5154af2c5e3af2e28fe..8da78932bd3e578fc2ba65ae70e77dbed8f1eaea 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridState.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/GridState.java
@@ -82,6 +82,7 @@ public final class GridState {
 
     void initGPar(GridDevice currentDevice) {
         devState.gpar = GPar.createNew(currentDevice);
+        assert devState.gpar.verify();
     }
 
     /**
@@ -120,6 +121,7 @@ public final class GridState {
     }
 
     public void setViewPort(RList viewPort) {
+        assert viewPort.verify();
         devState.viewPort = viewPort;
     }
 
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LGridDirty.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LGridDirty.java
index d24bea0560f6858231683a6e94b23cece372a147..8d865b9172905d35b33224d962037ef465cd0134 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LGridDirty.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LGridDirty.java
@@ -19,6 +19,13 @@ import com.oracle.truffle.r.nodes.builtin.RExternalBuiltinNode;
 import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames;
 import com.oracle.truffle.r.runtime.data.RNull;
 
+/**
+ * {@code L_gridDirty} is external that gets called before any grid operation, this is ensured by
+ * routing all external calls at R level through {@code grid.Call} function, which first invokes
+ * {@code L_gridDirty} before invoking the requested external. LGridDirty is responsible for delayed
+ * initialization of the grid state and device specific grid state if the device has changed since
+ * the last time.
+ */
 final class LGridDirty extends RExternalBuiltinNode {
     @Child private InitViewPortNode initViewPort = new InitViewPortNode();
 
@@ -39,28 +46,23 @@ final class LGridDirty extends RExternalBuiltinNode {
         // if no device has been opened yet, open the default one and make it current
         if (GridContext.getContext().getCurrentDevice() == null) {
             GridContext.getContext().openDefaultDevice();
-            gridState = GridContext.getContext().getGridState();    // grid state is device
-                                                                    // dependent
+            // grid state is device dependent
+            gridState = GridContext.getContext().getGridState();
         }
 
         // the current device has not been initialized yet...
         GridDevice device = GridContext.getContext().getCurrentDevice();
         device.openNewPage();
+        gridState.initGPar(device);
         gridState.setViewPort(initViewPort.execute(frame));
-        gridState.setDeviceInitialized();
-        if (gridState.getGpar() == null) {
-            gridState.initGPar(device);
-        }
-        if (gridState.getViewPort() == null) {
-            gridState.setViewPort(initViewPort.execute(frame));
-        }
         DisplayList.initDisplayList(gridState);
+        gridState.setDeviceInitialized();
         return RNull.instance;
     }
 
     @Override
     protected Object call(RArgsValuesAndNames args) {
-        // shadowed by the VirtualFrame overload
+        assert false : "should be shadowed by the overload with frame";
         return null;
     }
 }
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LNewPage.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LNewPage.java
index 917154715f4fecffe8d8b3ebb2c99adc9c018c4f..2f491ea4ccfaa8a626abc1e65684460dffc179df 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LNewPage.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LNewPage.java
@@ -11,19 +11,36 @@
  */
 package com.oracle.truffle.r.library.fastrGrid;
 
-import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
+import com.oracle.truffle.api.CompilerDirectives;
+import com.oracle.truffle.api.frame.VirtualFrame;
+import com.oracle.truffle.r.library.fastrGrid.device.GridDevice;
 import com.oracle.truffle.r.nodes.builtin.RExternalBuiltinNode;
+import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames;
 import com.oracle.truffle.r.runtime.data.RNull;
 
-final class LNewPage extends RExternalBuiltinNode.Arg0 {
+final class LNewPage extends RExternalBuiltinNode {
     static {
         Casts.noCasts(LNewPage.class);
     }
 
+    @Child private LGridDirty gridDirty = new LGridDirty();
+
+    @Override
+    public Object call(VirtualFrame frame, RArgsValuesAndNames args) {
+        GridDevice device = GridContext.getContext().getCurrentDevice();
+        if (GridContext.getContext().getGridState().isDeviceInitialized()) {
+            device.openNewPage();
+            return RNull.instance;
+        }
+        // There are some exceptions to the rule that any external call from grid R code is
+        // preceeded by L_gridDirty call, L_newpage is one of them.
+        CompilerDirectives.transferToInterpreter();
+        return gridDirty.call(frame, RArgsValuesAndNames.EMPTY);
+    }
+
     @Override
-    @TruffleBoundary
-    public Object execute() {
-        GridContext.getContext().getCurrentDevice().openNewPage();
-        return RNull.instance;
+    protected Object call(RArgsValuesAndNames args) {
+        assert false : "should be shadowed by the overload with frame";
+        return null;
     }
 }
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LUnsetViewPort.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LUnsetViewPort.java
index 0416b1f6746b01de0853d2a0d1c465683f893660..f23564cd261e1d0fcd634de7c4a43a9252753bbb 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LUnsetViewPort.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/LUnsetViewPort.java
@@ -76,7 +76,7 @@ public abstract class LUnsetViewPort extends RExternalBuiltinNode.Arg1 {
         gridState.setViewPort(newVp);
 
         // remove the parent link from the old viewport
-        gvp.setDataAt(gvp.getInternalStore(), ViewPort.PVP_PARENT, null);
+        gvp.setDataAt(gvp.getInternalStore(), ViewPort.PVP_PARENT, RNull.instance);
         return RNull.instance;
     }
 
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/GridDevice.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/GridDevice.java
index f893a5b02bc3bc37f1c998d71c265d50b6c86b6c..2ea6e4468e66e623d119819c643716f1ae1541a8 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/GridDevice.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/GridDevice.java
@@ -27,6 +27,9 @@ package com.oracle.truffle.r.library.fastrGrid.device;
  * in inches and angles in radians unless stated otherwise.
  */
 public interface GridDevice {
+    int DEFAULT_WIDTH = 720;
+    int DEFAULT_HEIGHT = 720;
+
     void openNewPage();
 
     /**
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/BufferedImageDevice.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/BufferedImageDevice.java
index 485ad251614d1fc06524ab20352361391b1060f9..577784461859f69a3c600497f361c1f5b141dd17 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/BufferedImageDevice.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/BufferedImageDevice.java
@@ -51,7 +51,9 @@ public final class BufferedImageDevice extends Graphics2DDevice {
             throw new NotSupportedImageFormatException();
         }
         BufferedImage image = new BufferedImage(width, height, TYPE_INT_RGB);
-        return new BufferedImageDevice(filename, fileType, image, (Graphics2D) image.getGraphics(), width, height);
+        Graphics2D graphics = (Graphics2D) image.getGraphics();
+        defaultInitGraphics(graphics);
+        return new BufferedImageDevice(filename, fileType, image, graphics, width, height);
     }
 
     @Override
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/BufferedJFrameDevice.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/BufferedJFrameDevice.java
index b94f4e39aa0864e6819430128b69eb432dd2439d..607b0ad8b033aca74cbdcc07b9d807e45b5cee5a 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/BufferedJFrameDevice.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/BufferedJFrameDevice.java
@@ -189,7 +189,7 @@ public final class BufferedJFrameDevice implements GridDevice, ImageSaver {
     }
 
     private void setGraphics(Graphics graphics) {
-        JFrameDevice.defaultInitGraphics((Graphics2D) graphics);
+        Graphics2DDevice.defaultInitGraphics((Graphics2D) graphics);
         inner.getGraphics2D().dispose();
         inner.setGraphics2D((Graphics2D) graphics);
     }
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/Graphics2DDevice.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/Graphics2DDevice.java
index 055084a451c858ad163dd07e432c2121f14c67b4..877ad16225a57d01b3ffe37ff2c6f05afdc45367 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/Graphics2DDevice.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/Graphics2DDevice.java
@@ -31,6 +31,7 @@ import java.awt.Font;
 import java.awt.FontMetrics;
 import java.awt.Graphics2D;
 import java.awt.Paint;
+import java.awt.RenderingHints;
 import java.awt.Shape;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Ellipse2D;
@@ -83,6 +84,11 @@ public class Graphics2DDevice implements GridDevice {
         this.graphicsIsExclusive = graphicsIsExclusive;
     }
 
+    static void defaultInitGraphics(Graphics2D graphics) {
+        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+        graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
+    }
+
     @Override
     public void openNewPage() {
         graphics.clearRect(0, 0, width, height);
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/JFrameDevice.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/JFrameDevice.java
index 93c4f700aa9bc9cbcfdc2b32e4e8ba48e4447063..7571ced32fe356ba76c1e85273c5231eed22a3d1 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/JFrameDevice.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/device/awt/JFrameDevice.java
@@ -26,7 +26,6 @@ import java.awt.BorderLayout;
 import java.awt.Dimension;
 import java.awt.Graphics2D;
 import java.awt.HeadlessException;
-import java.awt.RenderingHints;
 import java.awt.Toolkit;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
@@ -35,6 +34,7 @@ import javax.swing.JFrame;
 import javax.swing.JPanel;
 
 public final class JFrameDevice extends Graphics2DDevice {
+
     private final JFrame currentFrame;
     private final boolean disposeResources;
 
@@ -55,8 +55,8 @@ public final class JFrameDevice extends Graphics2DDevice {
      * Creates a standalone device that manages the window itself and closes it once
      * {@link #close()} gets called.
      */
-    public static JFrameDevice create() {
-        FastRFrame frame = new FastRFrame();
+    public static JFrameDevice create(int width, int height) {
+        FastRFrame frame = new FastRFrame(width, height);
         frame.setVisible(true);
         frame.pack();
         Graphics2D graphics = (Graphics2D) frame.getGraphics();
@@ -76,26 +76,20 @@ public final class JFrameDevice extends Graphics2DDevice {
         return currentFrame;
     }
 
-    static void defaultInitGraphics(Graphics2D graphics) {
-        graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
-        graphics.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
-    }
-
     static class FastRFrame extends JFrame {
         private static final long serialVersionUID = 1L;
-        private final Dimension framePreferredSize = new Dimension(720, 720);
         private final JPanel fastRComponent = new JPanel();
 
-        FastRFrame() throws HeadlessException {
+        FastRFrame(int width, int height) throws HeadlessException {
             super("FastR");
             addCloseListener();
-            createUI();
+            createUI(width, height);
             center();
         }
 
-        private void createUI() {
+        private void createUI(int width, int height) {
             setLayout(new BorderLayout());
-            setSize(framePreferredSize);
+            setSize(new Dimension(width, height));
             add(fastRComponent, BorderLayout.CENTER);
             fastRComponent.setPreferredSize(getSize());
         }
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/grDevices/InitWindowedDevice.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/grDevices/InitWindowedDevice.java
index 5048fe9411bad215e5a62392976c45f03821b8ba..40ceb214b586c8c18dd10cfa2495f11976083c1f 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/grDevices/InitWindowedDevice.java
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/grDevices/InitWindowedDevice.java
@@ -24,6 +24,7 @@ package com.oracle.truffle.r.library.fastrGrid.grDevices;
 
 import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
 import com.oracle.truffle.r.library.fastrGrid.GridContext;
+import com.oracle.truffle.r.library.fastrGrid.device.GridDevice;
 import com.oracle.truffle.r.library.fastrGrid.device.awt.BufferedImageDevice;
 import com.oracle.truffle.r.library.fastrGrid.device.awt.BufferedImageDevice.NotSupportedImageFormatException;
 import com.oracle.truffle.r.library.fastrGrid.device.awt.BufferedJFrameDevice;
@@ -40,6 +41,7 @@ import com.oracle.truffle.r.runtime.data.RNull;
  * . The arguments determine which device should be opened.
  */
 public final class InitWindowedDevice extends RExternalBuiltinNode {
+
     static {
         Casts.noCasts(InitWindowedDevice.class);
     }
@@ -47,28 +49,43 @@ public final class InitWindowedDevice extends RExternalBuiltinNode {
     @Override
     @TruffleBoundary
     protected Object call(RArgsValuesAndNames args) {
+        int width = getIntOrDefault(args, 1, GridDevice.DEFAULT_WIDTH);
+        int height = getIntOrDefault(args, 2, GridDevice.DEFAULT_HEIGHT);
         // if the first argument is a String, then it may describes the image format and filename to
         // use, the format is e.g. "jpeg::quality:filename"
         if (args.getLength() >= 1) {
             String name = RRuntime.asString(args.getArgument(0));
             if (!RRuntime.isNA(name) && name.contains("::")) {
-                return openImageDevice(name);
+                return openImageDevice(name, width, height);
             }
         }
-        // otherwise the
-        GridContext.getContext().setCurrentDevice(args.getLength() == 0 ? "awt" : "X11cairo", new BufferedJFrameDevice(JFrameDevice.create()));
+        // otherwise the windowed device
+        BufferedJFrameDevice device = new BufferedJFrameDevice(JFrameDevice.create(width, height));
+        String name = args.getArgument(0).equals(".FASTR.AWT") ? "awt" : "X11cairo";
+        GridContext.getContext().setCurrentDevice(name, device);
         return RNull.instance;
     }
 
-    private Object openImageDevice(String name) {
+    private Object openImageDevice(String name, int width, int height) {
         String formatName = name.substring(0, name.indexOf("::"));
         String filename = name.substring(name.lastIndexOf(':') + 1);
         try {
-            BufferedImageDevice device = BufferedImageDevice.open(filename, formatName, 700, 700);
+            BufferedImageDevice device = BufferedImageDevice.open(filename, formatName, width, height);
             GridContext.getContext().setCurrentDevice(formatName, device);
         } catch (NotSupportedImageFormatException e) {
             throw error(Message.GENERIC, String.format("Format '%s' is not supported.", formatName));
         }
         return RNull.instance;
     }
+
+    private static int getIntOrDefault(RArgsValuesAndNames args, int index, int defaultValue) {
+        if (index >= args.getLength()) {
+            return defaultValue;
+        }
+        int value = RRuntime.asInteger(args.getArgument(index));
+        if (RRuntime.isNA(value)) {
+            return defaultValue;
+        }
+        return value;
+    }
 }
diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/grDevices/R/fastrGridDevices.R b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/grDevices/R/fastrGridDevices.R
index 390bdacd81a88ad29531012f05a1cdf3e662103f..a1bc97886a6820163106b5418b8bff28506ee487 100644
--- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/grDevices/R/fastrGridDevices.R
+++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/fastrGrid/grDevices/R/fastrGridDevices.R
@@ -24,8 +24,8 @@ eval(expression({
     # For compatibility reasons, both X11 and awt end up calling C_X11.
     # In the future, this function may support extra parameters like a
     # reference to java 2D graphics object, which will be used for the drawing.
-    awt <- function(...) {
-        .External2(grDevices:::C_X11)
+    awt <- function(width = NULL, height = NULL) {
+        .External2(grDevices:::C_X11, ".FASTR.AWT", width, height)
     }
     # GnuR version only works with "X11cairo" device. Our version of savePlot
     # works with "awt" device and "X11cairo", which is for us only alias for