Code for next()