Refactoring extractIPAddress to avoid addition if checks.