(Contributed by Yufei Gu via Daniel Templeton) (cherry picked from commit f85b74ccf9f1c1c1444cc00750b03468cbf40fb9)