fixed overflow by 1 bug