integrated @khharut changes

with minor changes