Partial Python 2 rewrite