fix the off by one issues