Script refinements and cleanup