Refactored addToInventory