lab6 algorithm updated