Applying the chain rule twice