better socket disconnection and managed handling