Add condition on connection close