padding correction, refactoring