output_dir was not defined early enough. Fixed.