I'm not surprised you've had no answers yet, this is a non-question.
Your next is going to work whatever the current id.
You have not posted enough code to explain what your problem is, or to help solve that problem once it is clear.
Presumably you are after something that compares last to some base, and just returns base when less than base. So what is the problem?