Fix client ip collection

Fixes bugs in obtaining client IP address