Fix off by one in generating