Improve IP lookup logic.