added check for output file, needs fixing