Port amalgamate.py to Python 3.x