Algoritm changed