refactoring for endings and its paddings