add remote_ip and local_ip params instead of just 'ip'

Allow setting both remote and local ip's , with sane defaults.
Also some other random bugfixes by other colleagues.