optimize the algorithm

still failed with 132 nodes