Ported to Python 2