add boundary check.