Performance tuning, fix an inventory copying bug