refactored XML output code into smaller modules. still need to decide on term generation algorithm...