Automatically close all file handles in a hacky way (thanks cocotron)