Contributed by Bibin Chundatt and Eric Payne. (cherry picked from commit 647be0c0f69887afd7ad63aa1dfa6373a4b65ae6)