Fix off by one bug