ensure that all resources are closed

ensure that all resources are closed, connection has to be closed too.