Contributed by Dinesh Chitlangia. (cherry picked from commit c18eb9780163f8995c21b7d1b7b2b04140e4bc0a)