avoid setting of negative index