took care of out of bounds exceptions