Ported to python3.