Thanks dev@simon.net.nz for the suggestion and vijay_shanker for the patch. Backport of 1edef508 from master