check that indexes aren't nil before comparing