defer close in case of later error