diff --git a/Core/Instrument/DetectorMask.cpp b/Core/Instrument/DetectorMask.cpp
index 3eaab05c5c77ab7da349b2717f79ff9462470c0c..e045a5914d80f713007df8da2a4eebfe69e321b0 100644
--- a/Core/Instrument/DetectorMask.cpp
+++ b/Core/Instrument/DetectorMask.cpp
@@ -16,9 +16,7 @@
 #include "BornAgainNamespace.h"
 #include "IDetector2D.h"
 #include "Histogram2D.h"
-
-
-// InfinitePlane, Line, VerticalLine, HorizontalLine
+#include "RegionOfInterest.h"
 
 DetectorMask::DetectorMask()
     : m_number_of_masked_channels(0)
@@ -63,8 +61,14 @@ void DetectorMask::initMaskData(const IDetector2D& detector)
     assert(m_shapes.size() == m_mask_of_shape.size());
     m_mask_data.clear();
 
-    for (size_t dim=0; dim<detector.getDimension(); ++dim)
-        m_mask_data.addAxis(detector.getAxis(dim));
+    for (size_t dim=0; dim<detector.getDimension(); ++dim) {
+        const IAxis &axis = detector.getAxis(dim);
+//        if(detector.regionOfInterest()) {
+//            m_mask_data.addAxis(*detector.regionOfInterest()->clipAxisToRoi(dim, axis).get());
+//        } else {
+            m_mask_data.addAxis(axis);
+//        }
+    }
 
     process_masks();
 }
@@ -86,7 +90,7 @@ bool DetectorMask::isMasked(size_t index) const
         return false;
 
     if(index >= m_mask_data.getAllocatedSize())
-        throw Exceptions::RuntimeErrorException("DetectorMask::getMask() -> Error. "
+        throw Exceptions::RuntimeErrorException("DetectorMask::isMasked() -> Error. "
                                               "Index is out of range "+std::to_string(index));
     return m_mask_data[index];
 }
diff --git a/Core/Instrument/IDetector2D.cpp b/Core/Instrument/IDetector2D.cpp
index ace4686ca563ca2b57163bdc7de9d53acb56c4d7..20496cb5cc5471d3d216e5f6753d867318b732d2 100644
--- a/Core/Instrument/IDetector2D.cpp
+++ b/Core/Instrument/IDetector2D.cpp
@@ -147,11 +147,13 @@ const RegionOfInterest *IDetector2D::regionOfInterest() const
 void IDetector2D::setRegionOfInterest(double xlow, double ylow, double xup, double yup)
 {
     m_region_of_interest.reset(new RegionOfInterest(*this, xlow, ylow, xup, yup));
+    m_detector_mask.initMaskData(*this);
 }
 
 void IDetector2D::resetRegionOfInterest()
 {
     m_region_of_interest.reset();
+    m_detector_mask.initMaskData(*this);
 }
 
 void IDetector2D::removeMasks()
diff --git a/Core/Instrument/SimulationArea.cpp b/Core/Instrument/SimulationArea.cpp
index eabc39de21ebb8793d243c5f153cda7bf1a03e22..32a80073a2caf1869c0baa1864794e04f719f72f 100644
--- a/Core/Instrument/SimulationArea.cpp
+++ b/Core/Instrument/SimulationArea.cpp
@@ -34,7 +34,10 @@ SimulationArea::SimulationArea(const IDetector2D *detector)
         throw Exceptions::RuntimeErrorException(
             "SimulationArea::SimulationArea: detector is not two-dimensional");
 
-    m_max_index = m_detector->getTotalSize();
+    if(m_detector->regionOfInterest())
+        m_max_index = m_detector->regionOfInterest()->roiSize();
+    else
+        m_max_index = m_detector->getTotalSize();
 }
 
 SimulationAreaIterator SimulationArea::begin()
@@ -56,27 +59,20 @@ bool SimulationArea::isMasked(size_t index) const
         throw Exceptions::RuntimeErrorException(message.str());
     }
 
-    if(m_detector->regionOfInterest())
-        if(!m_detector->regionOfInterest()->isInROI(index)) return true;
-
-    return m_detector->isMasked(index);
+    return m_detector->getDetectorMask()->isMasked(detectorIndex(index));
 }
 
 size_t SimulationArea::roiIndex(size_t index) const
 {
-    if(!m_detector->regionOfInterest())
-        return index;
-
-    return m_detector->regionOfInterest()->roiIndex(index);
+    return index;
 }
 
 size_t SimulationArea::detectorIndex(size_t index) const
 {
-//    if(!m_detector->regionOfInterest())
-//        return index;
+    if(!m_detector->regionOfInterest())
+        return index;
 
-//    return m_detector->regionOfInterest()->detectorIndex(index);
-    return index;
+    return m_detector->regionOfInterest()->detectorIndex(index);
 }
 
 // --------------------------------------------------------------------------------------
@@ -87,10 +83,7 @@ SimulationRoiArea::SimulationRoiArea(const IDetector2D *detector)
 
 }
 
-bool SimulationRoiArea::isMasked(size_t index) const
+bool SimulationRoiArea::isMasked(size_t) const
 {
-    if(m_detector->regionOfInterest())
-        if(!m_detector->regionOfInterest()->isInROI(index)) return true;
-
     return false;
 }
diff --git a/Core/Instrument/SimulationArea.h b/Core/Instrument/SimulationArea.h
index 440b726da206c25944ab472dfc065ebfa66027bc..8c0c4ad612b2a6977466dfe7e0c22387217f0600 100644
--- a/Core/Instrument/SimulationArea.h
+++ b/Core/Instrument/SimulationArea.h
@@ -64,7 +64,7 @@ class BA_CORE_API_ SimulationRoiArea : public SimulationArea
 public:
     explicit SimulationRoiArea(const IDetector2D *detector);
 
-    virtual bool isMasked(size_t index) const;
+    virtual bool isMasked(size_t) const;
 
 };
 
diff --git a/Tests/UnitTests/Core/3/SimulationAreaTest.h b/Tests/UnitTests/Core/3/SimulationAreaTest.h
index fb0a7b9f402cdcaace5da79cd2d788db158b55d4..75972b153c8d3f6091e88d27a1bebe2ec55673b3 100644
--- a/Tests/UnitTests/Core/3/SimulationAreaTest.h
+++ b/Tests/UnitTests/Core/3/SimulationAreaTest.h
@@ -152,19 +152,23 @@ TEST_F(SimulationAreaTest, maskAndRoiIteration)
     detector.addMask(Geometry::Rectangle(-0.9, 0.1, 0.9, 1.9), true);
     SimulationArea area(&detector);
 
-    std::vector<int> expectedIndexes = {6, 7, 9, 10, 11, 13, 14, 15};
+    std::vector<int> expectedRoiIndexes = {1, 2, 3, 4, 5, 6, 7, 8};
+    std::vector<int> expectedDetectorIndexes = {6, 7, 9, 10, 11, 13, 14, 15};
     std::vector<int> expectedElementIndexes = {0, 1, 2, 3, 4, 5, 6, 7};
     std::vector<int> indexes;
     std::vector<int> elementIndexes;
     std::vector<int> detectorIndexes;
+    std::vector<int> roiIndexes;
     for(SimulationArea::iterator it = area.begin(); it!=area.end(); ++it) {
         indexes.push_back(it.index());
         elementIndexes.push_back(it.elementIndex());
         detectorIndexes.push_back(it.detectorIndex());
+        roiIndexes.push_back(it.roiIndex());
     }
-    EXPECT_EQ(indexes, expectedIndexes);
+    EXPECT_EQ(indexes, expectedRoiIndexes);
     EXPECT_EQ(elementIndexes, expectedElementIndexes);
-    EXPECT_EQ(detectorIndexes, expectedIndexes);
+    EXPECT_EQ(detectorIndexes, expectedDetectorIndexes);
+    EXPECT_EQ(roiIndexes, expectedRoiIndexes);
 }
 
 //! Checking index of ROI
@@ -176,7 +180,8 @@ TEST_F(SimulationAreaTest, indexInRoi)
     detector.addMask(Geometry::Rectangle(-0.9, 0.1, 0.9, 1.9), true);
     SimulationArea area(&detector);
 
-    std::vector<int> expectedIndexes = {6, 7, 9, 10, 11, 13, 14, 15};
+    std::vector<int> expectedIndexes = {1, 2, 3, 4, 5, 6, 7, 8};
+    std::vector<int> expectedDetectorIndexes = {6, 7, 9, 10, 11, 13, 14, 15};
     std::vector<int> expectedElementIndexes = {0, 1, 2, 3, 4, 5, 6, 7};
     std::vector<int> expectedRoi = {1, 2, 3, 4, 5, 6, 7, 8};
     std::vector<int> indexes;
@@ -192,7 +197,7 @@ TEST_F(SimulationAreaTest, indexInRoi)
     EXPECT_EQ(indexes, expectedIndexes);
     EXPECT_EQ(elementIndexes, expectedElementIndexes);
     EXPECT_EQ(roiIndexes, expectedRoi);
-    EXPECT_EQ(detectorIndexes, expectedIndexes);
+    EXPECT_EQ(detectorIndexes, expectedDetectorIndexes);
 }
 
 #endif
diff --git a/Tests/UnitTests/Core/3/SphericalDetectorTest.h b/Tests/UnitTests/Core/3/SphericalDetectorTest.h
index 80f1c8128c27810438aabf2f7cfa3fda1a6ec6c2..bc116bf56e686b655b1ff40067b71d7c736e4d5d 100644
--- a/Tests/UnitTests/Core/3/SphericalDetectorTest.h
+++ b/Tests/UnitTests/Core/3/SphericalDetectorTest.h
@@ -355,15 +355,15 @@ TEST_F(SphericalDetectorTest, Clone)
 
     // checking iteration over the map of cloned detector
     SimulationArea area(clone.get());
-    std::vector<int> expectedIndexes = {6, 9, 10, 13, 14, 17};
+    std::vector<int> expectedDetectorIndexes = {6, 9, 10, 13, 14, 17};
     std::vector<int> expectedElementIndexes = {0, 1, 2, 3, 4, 5};
-    std::vector<int> indexes;
+    std::vector<int> detectorIndexes;
     std::vector<int> elementIndexes;
     for(SimulationArea::iterator it = area.begin(); it!=area.end(); ++it) {
-        indexes.push_back(it.index());
+        detectorIndexes.push_back(it.detectorIndex());
         elementIndexes.push_back(it.elementIndex());
     }
-    EXPECT_EQ(indexes, expectedIndexes);
+    EXPECT_EQ(detectorIndexes, expectedDetectorIndexes);
     EXPECT_EQ(elementIndexes, expectedElementIndexes);
 }
 
diff --git a/dev-tools/log/perf_history.txt b/dev-tools/log/perf_history.txt
index d3a2e42f78680a23b418c5c9149dece9f2a384b4..00e6a6155f856560b979fc88da56bd4cb77ac5a8 100644
--- a/dev-tools/log/perf_history.txt
+++ b/dev-tools/log/perf_history.txt
@@ -547,3 +547,10 @@
 | date                | hostname | sysinfo      | python | total cpu | total wall | MultiLayer | CylindersInDWBA | RotatedPyramids | CoreShell | SquareLattice | RadialParaCrystal | HexParaCrystal | SSCA   | Mesocrystal | PolMagCyl | Custom FF |
 | 2016-10-24 13:27:17 | scgsun   | Linux x86_64 | 2.7    | 120.7920  | 19.2657    | 2.8666     | 0.6583          | 3.3504          | 0.4888    | 2.3131        | 0.6682            | 3.2659         | 1.1200 | 1.9051      | 1.7457    | 0.8838    |
 
+
+# after switch to SimulationAreaIterator based on ROI
+
+| date                | hostname | sysinfo      | python | total cpu | total wall | MultiLayer | CylindersInDWBA | RotatedPyramids | CoreShell | SquareLattice | RadialParaCrystal | HexParaCrystal | SSCA   | Mesocrystal | PolMagCyl | Custom FF |
+| 2016-10-25 17:19:59 | scgsun   | Linux x86_64 | 2.7    | 121.3720  | 18.5189    | 2.8794     | 0.5891          | 3.2295          | 0.4259    | 2.2341        | 0.5990            | 3.4064         | 0.8513 | 1.7682      | 1.6408    | 0.8952    |
+| 2016-10-25 17:20:43 | scgsun   | Linux x86_64 | 2.7    | 120.4280  | 18.1926    | 2.8557     | 0.5722          | 3.2113          | 0.4582    | 2.2046        | 0.5936            | 3.2125         | 0.8494 | 1.7489      | 1.6168    | 0.8694    |
+