From the square root, the derivative of std is infinity at std=0. I would recommend working around it by using a backward hook and where. Or you could spell out the std and regularize before the square root.
Best regards
Thomas