Improved socket code and API.