Small changes of algorithm