bug fixed: closing output file