Fixed bug in calculating padding size