Improve python3 compatibility with next() built-in