bugfix (off by one) and misnamed variable