seperate function to handle tcp_closed