Thanks Sai Krishna for the initial patch. Backport of 7d485d5d75bd9faab0b949fd34d4f098f8079452 from master