attemp to improve the algorithm