flat_correct doesn't normalize flat field for uncertainty array
When using flat_correct on an image with an uncertainty array the flat field is normalized before the data is divided through it, but not for the uncertainty array. 

diff --git a/CHANGES.rst b/CHANGES.rst
index 33b7de6..c3d31a1 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -25,6 +25,8 @@ Bug Fixes
 - ``Combiner`` creates plain array uncertainties when using``average_combine``
   or ``median_combine``. [#351]
 
+- ``flat_correct`` does not properly scale uncertainty in the flat. [#345, #363]
+
 1.0.1 (2016-03-15)
 ------------------
 
diff --git a/ccdproc/core.py b/ccdproc/core.py
index 74d307d..34fac91 100644
--- a/ccdproc/core.py
+++ b/ccdproc/core.py
@@ -705,11 +705,12 @@ def flat_correct(ccd, flat, min_value=None):
         flat_min.data[flat_min.data < min_value] = min_value
         use_flat = flat_min
 
+    # Normalize the flat.
+    flat_mean = use_flat.data.mean() * use_flat.unit
+    flat_normed = use_flat.divide(flat_mean)
+
     # divide through the flat
-    flat_corrected = ccd.divide(use_flat)
-    # multiply by the mean of the flat
-    flat_corrected = flat_corrected.multiply(use_flat.data.mean() *
-                                             use_flat.unit)
+    flat_corrected = ccd.divide(flat_normed)
 
     flat_corrected.meta = ccd.meta.copy()
     return flat_corrected
diff --git a/ccdproc/tests/test_ccdproc.py b/ccdproc/tests/test_ccdproc.py
index 9753760..3cdb2f9 100644
--- a/ccdproc/tests/test_ccdproc.py
+++ b/ccdproc/tests/test_ccdproc.py
@@ -400,24 +400,33 @@ def test_flat_correct(ccd_data):
 
 
 # test for flat correction with min_value
-@pytest.mark.data_scale(10)
+@pytest.mark.data_scale(1)
+@pytest.mark.data_mean(5)
 def test_flat_correct_min_value(ccd_data):
     size = ccd_data.shape[0]
+
     # create the flat
     data = 2 * np.random.normal(loc=1.0, scale=0.05, size=(size, size))
     flat = CCDData(data, meta=fits.header.Header(), unit=ccd_data.unit)
     flat_orig_data = flat.data.copy()
     min_value = 2.1  # should replace some, but not all, values
-    flat_data = flat_correct(ccd_data, flat, min_value=min_value)
+    flat_corrected_data = flat_correct(ccd_data, flat, min_value=min_value)
     flat_with_min = flat.copy()
     flat_with_min.data[flat_with_min.data < min_value] = min_value
-    #check that the flat was normalized
-    np.testing.assert_almost_equal((flat_data.data * flat_with_min.data).mean(),
-                                   ccd_data.data.mean() * flat_with_min.data.mean())
-    np.testing.assert_allclose(ccd_data.data / flat_data.data,
+
+    # Check that the flat was normalized. The asserts below, which look a
+    # little odd, are correctly testing that
+    #    flat_corrected_data = ccd_data / (flat_with_min / mean(flat_with_min))
+    np.testing.assert_almost_equal(
+        (flat_corrected_data.data * flat_with_min.data).mean(),
+        (ccd_data.data * flat_with_min.data.mean()).mean()
+    )
+    np.testing.assert_allclose(ccd_data.data / flat_corrected_data.data,
                                flat_with_min.data / flat_with_min.data.mean())
+
     # Test that flat is not modified.
     assert (flat_orig_data == flat.data).all()
+    assert flat_orig_data is not flat.data
 
 
 # test for deviation and for flat correction
@@ -433,6 +442,16 @@ def test_flat_correct_deviation(ccd_data):
     flat = create_deviation(flat, readnoise=0.5 * u.electron)
     ccd_data = flat_correct(ccd_data, flat)
 
+# test the uncertainty on the data after flat correction
+def test_flat_correct_data_uncertainty():
+    # Regression test for #345
+    dat = CCDData(np.ones([100, 100]), unit='adu',
+                  uncertainty=np.ones([100, 100]))
+    # Note flat is set to 10, error, if present, is set to one.
+    flat = CCDData(10 * np.ones([100, 100]), unit='adu')
+    res = flat_correct(dat, flat)
+    assert (res.data == dat.data).all()
+    assert (res.uncertainty.array == dat.uncertainty.array).all()
 
 # tests for gain correction
 def test_gain_correct(ccd_data):
@@ -834,7 +853,7 @@ def test_ccd_process():
                        master_flat=masterflat, dark_frame=dark_frame,
                        bad_pixel_mask=mask, gain=0.5 * u.electron/u.adu,
                        readnoise=5**0.5 * u.electron, oscan_median=True,
-                       dark_scale=False, dark_exposure=1.*u.s, 
+                       dark_scale=False, dark_exposure=1.*u.s,
                        data_exposure=1.*u.s)
 
     # final results should be (10 - 2) / 2.0 - 2 = 2
['ccdproc/core.py', 'ccdproc/tests/test_ccdproc.py', 'CHANGES.rst']