Refactored scripts / modify and write output