Fix the previous version which ignored the output_file parameter and instead generated its own name for the output file. Fix a bug in the drift correction part of the code.