implement product replacement algorithm