Add in check for connection being closed