fix possible memory bug when deleting/creating connections