Modified to choose output file handler