Added on support for only closing files if the handle was valid