Fix the algorithm
Fix bugs