Updated error checking for out of bounds indicies