After trying several algorithms, found a very fast one that works consistently