added logic to consider sold items