Changed algorithm ever so slightly