adding some checks to prevent overflow on item generation