Fixed some bugs in next.