fixed minor issue in writing to file