Added improvements in algorithm.