make some changes suggested in #1107 to improve open file handles