Changing the logic with the pad and small enhancements on the algorithm.