Updated output to script which vastly simplifies code