Merged code for ip check