fix next() to work properly