code refactored for better pad/layout separation