more cart-package algorithm, refactored style