attempt to improve the algorithm