Sorry for the rewrite here, but I felt the original function was too obtuse and hard to read. I'll rewrite this to fix the false positives.