Porting to Python 2.x

And more functional programming style. :)