Inefficiencies of this algorithm