Little changing of algorithm