some refactoring of chain_manager