Improved algorithm with fewer false positives

Thank you @infograf768 and @brianteeman