fix some off by one panicks