improve counterdiff.py