use defer to close