Fixed off by one error

Probably a hackish change, please test before merging.