minor rewrite in rewrite.py