improve treatment of chain rule