fixed inventory replenishment, added some tests