Overflow error in new "next" function. Works otherwise