Added disconnecting and socket rebind.
Improved error handling.