Fix to ensure we dont leave any open file handles laying around