Ported to Python 2.x