add build_chain method and refactor