new, generic algorhithm wip