Actually, I think it has to be done the way I did it, because ``f`` is not necessarily opened in the function (it depends on what the user passes) so it makes it harder to design a ``with`` statement. I made sure it's always closed before any exception where it might already be opened.