From my POV, this is the minimal needed change. From your POV, refactoring is needed. You might be right, I didn't like the CheckIP(...) function at all when I saw it.