fix the source detection; some optimization in the InventoryUtils