avoid 'index out of range' error