diff --git a/sleepyhead/Graphs/gLineChart.cpp b/sleepyhead/Graphs/gLineChart.cpp
index 028c3100..e70fe8b1 100644
--- a/sleepyhead/Graphs/gLineChart.cpp
+++ b/sleepyhead/Graphs/gLineChart.cpp
@@ -428,8 +428,6 @@ void gLineChart::paint(QPainter &painter, gGraph &w, const QRegion &region)
 
     w.roundY(miny, maxy);
 
-
-
 //#define DEBUG_AUTOSCALER
 #ifdef DEBUG_AUTOSCALER
     QString a = QString().sprintf("%.2f - %.2f",miny, maxy);
diff --git a/sleepyhead/SleepLib/event.cpp b/sleepyhead/SleepLib/event.cpp
index 0451f513..b236ead9 100644
--- a/sleepyhead/SleepLib/event.cpp
+++ b/sleepyhead/SleepLib/event.cpp
@@ -169,7 +169,7 @@ void EventList::AddWaveform(qint64 start, qint16 *data, int recs, qint64 duratio
     if (m_update_minmax) {
         EventDataType min = m_min, max = m_max, val, gain = m_gain;
 
-        for (int i=0; i < recs; ++i ) {
+        for (int i=0; i < recs; ++i) {
             m_data[r++] = raw = *sp++;
             val = EventDataType(raw) * gain + m_offset;
             if (min > val) { min = val; }
diff --git a/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp b/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp
index 34c73635..2ba0cd3a 100644
--- a/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp
+++ b/sleepyhead/SleepLib/loader_plugins/resmed_loader.cpp
@@ -2647,8 +2647,15 @@ bool ResmedLoader::LoadBRP(Session *sess, const QString & path)
             EventList *a = sess->AddEventList(code, EVL_Waveform, es.gain, es.offset, 0, 0, rate);
             a->setDimension(es.physical_dimension);
             a->AddWaveform(edf.startdate, es.data, recs, duration);
-            sess->setMin(code, a->Min());
-            sess->setMax(code, a->Max());
+            EventDataType min = a->Min();
+            EventDataType max = a->Max();
+
+            // Cap to physical dimensions, because there can be ram glitches/whatever that throw really big outliers.
+            if (min < es.physical_minimum) min = es.physical_minimum;
+            if (max > es.physical_maximum) max = es.physical_maximum;
+
+            sess->setMin(code, min);
+            sess->setMax(code, max);
             sess->setPhysMin(code, es.physical_minimum);
             sess->setPhysMax(code, es.physical_maximum);
         }