my pad solution refactored