A few changes to make the algorithm run better.