socks-proxy-agent: small code cleanup

Removes one layer of indentation, and cleans up logic by using named functions.