made separate function to close file