avoid index out of bound exception