Restructure input code to seperate out CSV specific code