Refactor inventory handling.