Edited is_valid_ip for readability