new algorithm2
fix little bug