update and fix chain.py