refactored the program code out of printout script to make it more readable.