Algorithm explained