refactor to close File automatically using File do block