more cleanup and script refinement