Fixed deadlock & issue with detecting IP address

Now detects correct local IPv4 address
Infinite loop caused lock to never be released