SOCKS proxy support: loads of fixes