Fix off-by-one bug
Merge with head