only call file.Close() instead of bundling it in a function