Fixed off-by-3 bug