Fix off-by-one error.

Change-Id: I6d4f41ebb5fdaef45305a3050bee13c7d8314e5c
Fix NullPointerException.

Change-Id: Ia79d9a5e3568c2d5d47c4e87df6b832c4775a263