Fix boundary check