Improve detection for non-cidr masks to prevent unwanted matches

Fixes issue #762 reported by @neoinr