Added output file handling