algorithm double-checked