add option for keeping temporary files
refactor output module