defined next() function