Improved code for ZEN-11583 issue