Change improved algorithm