add the boundary check of rows