rewrite contractAndFilter.py