adds protection for negative values in repeat statements