refactor and add xml gen