Tremendously improved algorithm; single core and parallel versions.