Review and changes from Jocelyn Fiat

Maybe such function could be rewritten as reusable component for EWF since it may be a common need
but for now, it is not.