Fix boundary check.