improved remote IP address retrieval logic