add improved algorithm