ERT-593 Refactoring of code + bug fix in Gen_Kw export