improvement of algorithm