fixed flatten.py