refactored to handle invalid IPv4 address