original script
reformat
a few cleanups