Close connections when needed