much faster algo, helper scripts