Fix chain code handling