Cleaned socket code