diff --git a/CAL/CalibrationProcessing/bin/preprocess_holography_dataset.py b/CAL/CalibrationProcessing/bin/preprocess_holography_dataset.py
index f562071f3f3c69f7fddec53d346b3563122bbaa8..5476e36c7c87e2d6e6ef3055995644c583452bbd 100644
--- a/CAL/CalibrationProcessing/bin/preprocess_holography_dataset.py
+++ b/CAL/CalibrationProcessing/bin/preprocess_holography_dataset.py
@@ -5,6 +5,7 @@ import logging
 from lofar.calibration.common.utils import *
 import lofar.calibration.processing as processing
 import sys
+
 DEFAULT_SLEEP_TIME = 1
 
 logger = logging.getLogger('mshologextract')
@@ -29,7 +30,7 @@ def parse_command_line_arguments_and_set_verbose_logging(parser):
     :return: the parsed arguments
     :rtype: argparse.Namespace
     """
-    arguments=parser.parse_args()
+    arguments = parser.parse_args()
     if arguments.v:
         logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s', level=logging.DEBUG)
 
@@ -64,6 +65,20 @@ def specify_command_line_arguments():
     return parser
 
 
+def average_by_sample(input_path, average_samples):
+    logger.info('Averaging %s with a sample window of %s', input_path, average_samples)
+    output_hds = processing.average_dataset_by_sample(input_path, average_samples)
+    logger.info('Averaged %s with a sample window of %s', input_path, average_samples)
+    return output_hds
+
+
+def average_by_time_interval(input_path, time_interval):
+    logger.info('Averaging %s with a time sample window of %s s', input_path, time_interval)
+    output_hds = processing.average_dataset_by_time(input_path, time_interval)
+    logger.info('Averaged %s with a time sample window of %s', input_path, time_interval)
+    return output_hds
+
+
 def preaverage_holography_dataset(input_path, output_path, average_samples, time_average_step):
     """
 
@@ -79,26 +94,18 @@ def preaverage_holography_dataset(input_path, output_path, average_samples, time
                      ' or the time average step in seconds')
         raise ValueError('Both average_samples and time_average_step have been specified')
 
-    if average_samples is None and time_average_step is None:
-        logger.error('Neither average_samples nor time_average_step has been specified')
-
     if average_samples is not None:
-        logger.info('Averaging %s with a time sample window of %s', input_path, average_samples)
-        output_hds = processing.average_dataset_by_sample(input_path, average_samples)
-        logger.info('Averaged %s with a time sample window of %s', input_path, time_average_step)
-
-        logger.info('Storing processed file %s in %s', input_path, output_path)
-        output_hds.store_to_file(output_path)
-        logger.info('Stored processed file %s in %s', input_path, output_path)
+        output_hds = average_by_sample(input_path, average_samples)
+    elif time_average_step is not None:
+        output_hds = average_by_time_interval(input_path, time_average_step)
+    else:
+        logger.error('Neither average_samples nor time_average_step has been specified')
+        raise ValueError('Neither average_samples nor time_average_step has been specified')
 
-    if time_average_step is not None:
-        logger.info('Averaging %s with a time sample window of %s s', input_path, time_average_step)
-        output_hds = processing.average_dataset_by_time(input_path, time_average_step)
-        logger.info('Averaged %s with a time sample window of %s', input_path, time_average_step)
+    logger.info('Storing processed file %s in %s', input_path, output_path)
+    output_hds.store_to_file(output_path)
+    logger.info('Stored processed file %s in %s', input_path, output_path)
 
-        logger.info('Storing processed file %s in %s', input_path, output_path)
-        output_hds.store_to_file(output_path)
-        logger.info('Stored processed file %s in %s', input_path, output_path)
 
 if __name__ == '__main__':
-    main()
\ No newline at end of file
+    main()