Refine the item collecting code.