Algorythm fix: two cases