Copy/pasted from unified_inventory, with a few changes.